0% found this document useful (0 votes)
17 views

FDS Assignment3

This document contains the code for a Python program that performs operations on matrices. It defines functions to accept a matrix from user input, display a matrix, add two matrices, subtract two matrices, multiply two matrices, and find the transpose of a matrix. The main function contains a loop that prints a menu with the matrix operation options for the user to select from.

Uploaded by

Yashwant Reddy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

FDS Assignment3

This document contains the code for a Python program that performs operations on matrices. It defines functions to accept a matrix from user input, display a matrix, add two matrices, subtract two matrices, multiply two matrices, and find the transpose of a matrix. The main function contains a loop that prints a menu with the matrix operation options for the user to select from.

Uploaded by

Yashwant Reddy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

NAME : SIDDHARTH GANESH MARNE

ROLL NO : COSB49

Assignment : 03
1 def accept_matrix(M) :
PROGRAM:-
2
3
print("\nEnter the order of the Matrix (row,col) : ")
r = int(input("\trow = "))
4 c = int(input("\tcol = "))
5 print("Enter the elements of the Matrix : \n")
6 for i in range(r) :
7 A = []
8 for j in range (c) :
9 A.append(int(input()))
10 M.append(A)
11 print("\nMatrix accepted successfully\n")
12
13
14 def display_matrix(M,r,c):
15 print("Matrix (%d,%d) : "%(r,c))
16 for i in range(r) :
17 print("\t\t",end=' ')
18 for j in range(c):
19 print("%3d"%M[i][j],end=' ')
20 print("")
21
22
23 def addition_matrix(M1,M2,M3,r,c) :
24 for i in range(r) :
25 A = []
26 for j in range(c):
27 A.append(M1[i][j] + M2[i][j])
28 M3.append(A)
29
30 def substraction_matrix(M1,M2,M3,r,c) :
31 for i in range(r) :
32 A = []
33 for j in range(c):
34 A.append(M1[i][j] - M2[i][j])
35 M3.append(A)
36
37
38 def multiplication_matrix(M1,M2,M3,r1,c1,c2) :
39 for i in range(r1) :
40 A = []
41 for j in range(c2) :
42 sum = 0
43 for k in range(c1) :
44 sum = sum + (M1[i][k] * M2[k][j])
45 A.append(sum)
46 M3.append(A)
47
48 def find_transpose_matrix(M,r,c,T) :
49 for i in range(c):
50 A = []
51 for j in range(r):
52 A.append(M[j][i])
53 T.append(A)
54
55 def main():
56 while True :
57 print("\t\t\t1: Accept Matrix");
58 print("\t\t\t2: Display Matrix");

You might also like