Questions
Write a python program to add two dimensional matrices.
Last Updated : 26 Jul 2026
Jan 22
Solution:
# Define two 3x3 matrices
matrix_A = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
matrix_B = [
[9, 8, 7],
[6, 5, 4],
[3, 2, 1]
]
# Initialize a result matrix filled with zeros
result = [
[0, 0, 0],
[0, 0, 0],
[0, 0, 0]
]
# Iterate through each row
for i in range(len(matrix_A)):
# Iterate through each column
for j in range(len(matrix_A[0])):
result[i][j] = matrix_A[i][j] + matrix_B[i][j]
# Display the addition result
print("Resulting Matrix:")
for row in result:
print(row)
Report an error