Skip to content

Commit fd8b2ef

Browse files
authored
matrix addition
1 parent 8b7c07f commit fd8b2ef

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

matrix addition

+22
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)