FDS Assignment 03
FDS Assignment 03
CODE :-
def accept_matrix(M):
print("\nEnter the order of the Matrix (row,col):")
r= int(input("\trow = ")) c= int(input("\tcol =")) print("Enter
the elements of the Matrix : \n")
for i in range(r): A=[] for j in range(c):
A.append(int(input()))
M.append(A) print("\nMatrix accepted
successfully\n")
def display_matrix(M,r,c):
print("Matrix (%d,%d): "%(r,c))
for i in range(r): print("\t\
t",end='')
for j in range(c):
print("%3d"%M[i][j],end='')
print(" ")
def addition_matrix(M1,M2,M3,r,c):
for i in range (r): A=[] for j in range
(c):
A.append(M1[i][j]+M2[i][j])
M3.append(A)
def substraction_matrix(M1,M2,M3,r,c):
for i in range (r): A=[] for j in range (c):
A.append(M1[i][j]-M2[i][j])
M3.append(A)
def multiplication_matrix(M1,M2,M3,r1,c1,c2):
for i in range(r1): A=[] for j in range(c2):
sum=0 for k in range(c1):
sum=sum+(M1[i][k]*M2[k][j])
A.append(sum)
M3.append(A)
def find_transpose_matrix(M,r,c,T):
for i in range(c): A=[] for j in
range(r):
A.append(M[j][i])
T.append(A)
def main():
while True:
print("\t\t\t1: Accept Matrix");
print("\t\t\t2: Display Matrix"); print("\t\t\t3:
Addition of Matrices"); print("\t\t\t4:
SUbstraction of Matrices"); print("\t\t\t5:
Multiplication of Matrices"); print("\t\t\t6:
Transpose Matrix"); print("\t\t\t7: Exit");
else:
print("Wrong choice entered !! Try again")
main()
Output –
1: Accept Matrix
2: Display Matrix
3: Addition of Matrices
4: SUbstraction of Matrices
5: Multiplication of
Matrices
6: Transpose Matrix
7: Exit
Enter your choice:1
Input First Matrix
1
2
3
4
5
6
Matrix accepted successfully
1: Accept Matrix
2: Display Matrix
3: Addition of Matrices
4: SUbstraction of Matrices
5: Multiplication of Matrices
6: Transpose Matrix
7:
Exit Enter your
choice:2 First Matrix
(3,2):
12
34
56
Second Matrix (3,2):
78
94
52
1: Accept Matrix
2: Display Matrix
3: Addition of Matrices
4: SUbstraction of Matrices
5: Multiplication of Matrices
6: Transpose Matrix
7: Exit
Enter your choice:3
FirstMatrix (3,2):
12
34
56
SecondMatrix (3,2):
78
94
52
Addition
Matrix (3,2):
8 10
12 8
10 8
1: Accept Matrix
2: Display Matrix
3: Addition of Matrices
4: SUbstraction of Matrices
5: Multiplication of Matrices
6: Transpose Matrix
7: Exit
Enter your choice:4
FirstMatrix (3,2):
12
34
56
SecondMatrix (3,2):
78
9 4
52
Substraction
Matrix (3,2):
-6 -6
-6 0
04
1: Accept Matrix
2: Display Matrix
3: Addition of Matrices
4: SUbstraction of Matrices
5: Multiplication of Matrices
6: Transpose Matrix
7: Exit Enter your choice:5
FirstMatrix (3,2):
12
34
5 6 SecondMatrix
(3,2):
78
94
52
Multiplication not possible
1: Accept Matrix
2: Display Matrix
3: Addition of Matrices
4: SUbstraction of Matrices
5: Multiplication of Matrices
6: Transpose Matrix
7: Exit
Enter your choice:6
FirstMatrix (3,2):
12
34
5 6
TransposeMatrix (2,3): 135
246
SecondMatrix (3,2):
78
94
5 2
TransposeMatrix (2,3): 795
842
1: Accept Matrix
2: Display Matrix
3: Addition of Matrices
4: SUbstraction of Matrices
5: Multiplication of Matrices
6: Transpose Matrix
7: Exit
Enter your choice:7
End of Program