Skip to content

Commit 891bb5b

Browse files
Create Addition of Two matrices
In this program we have used nested for loops to iterate through each row and each column. At each point, we add the corresponding elements in the two matrices and store it in the result.
1 parent 99cf7d7 commit 891bb5b

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

‎Addition of Two matrices‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Program to add two matrices using nested loop
2+
3+
X = [[12,7,3],
4+
[4 ,5,6],
5+
[7 ,8,9]]
6+
7+
Y = [[5,8,1],
8+
[6,7,3],
9+
[4,5,9]]
10+
11+
result = [[0,0,0],
12+
[0,0,0],
13+
[0,0,0]]
14+
15+
# iterate through rows
16+
for i in range(len(X)):
17+
# iterate through columns
18+
for j in range(len(X[0])):
19+
result[i][j] = X[i][j] + Y[i][j]
20+
21+
for r in result:
22+
print(r)

0 commit comments

Comments
 (0)