-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatrix_Addition.py
More file actions
47 lines (36 loc) · 1004 Bytes
/
Matrix_Addition.py
File metadata and controls
47 lines (36 loc) · 1004 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
rows = int(input("Enter Row Size: "))
cols = int(input("Enter Column Size: "))
matrix1 = []
matrix2 = []
sum_matrix = []
for i in range(rows):
row1 = []
for j in range(cols):
elements_of_1st_matrix = int(input(f"Enter 1st Matrix Elements at position [{i}][{j}]: "))
row1.append(elements_of_1st_matrix)
matrix1.append(row1)
print()
for i in range(rows):
row2 = []
for j in range(cols):
elements_of_2nd_matrix = int(input(f"Enter 2nd Matrix Elements at position [{i}][{j}]: "))
row2.append(elements_of_2nd_matrix)
matrix2.append(row2)
print()
for i in range(rows):
row3 = []
for j in range(cols):
addition = matrix1[i][j] + matrix2[i][j]
row3.append(addition)
sum_matrix.append(row3)
print("1st Matrix is:")
for x in matrix1:
print(x)
print()
print("2nd Matrix is:")
for y in matrix2:
print(y)
print()
print("Addition Of 1st and 2nd Matrix is:")
for z in sum_matrix:
print(z)