In [1]:
A = []B = []r1 = int(input('Enter the number of rows of first matrix: '))c1 = int(input('Enter the number of cloumns of first matrix: '))print('Enter the elements of the first matrix: ')for i in range(0, r1): row = [] for j in range(0, c1): row.append(int(input())) A.append(row)print ('First entered matrix is: ')for i in range(0, r1): for j in range(0, c1): print(A[i][j], end = " ") print()r2 = int(input('Enter the number of rows of second matrix: '))c2 = int(input('Enter the number of columns of second matrix: '))print ('Enter the elements of the second entered matrix: ')for i in range(0, r2): row = [] for j in range(0, c2): row.append(int(input())) B.append(row) print ('Second entered matrix is: ')for i in range(0, r2): for j in range(0, c2): print (B[i][j], end = " ") print()if r1 != r2 and c1 != c2: print('Addition is not possible because the dimensions are not same')else: print('Addition is possible.') res = [] for i in range(0, r1): row = [] for j in range(0, c1): row.append(A[i][j] + B[i][j]) res.append(row) print ('Summation of the two given matrix is: ') for i in range(0, r1): for j in range(0, c1): print (res[i][j], end = " ") print() Enter the number of rows of first matrix: 2 Enter the number of cloumns of first matrix: 3 Enter the elements of the first matrix: 3 4 5 4 5 6 First entered matrix is: 3 4 5 4 5 6 Enter the number of rows of second matrix: 2 Enter the number of columns of second matrix: 3 Enter the elements of the second entered matrix: 4 5 6 6 7 8 Second entered matrix is: 4 5 6 6 7 8 Addition is possible. Summation of the two given matrix is: 7 9 11 10 12 14
Thank you very much.
ReplyDelete