Given size N (N x N), matrix A and matrix B, multiply the two matrices and print the resultant matrix.
Output:
Enter the value of N for N x N: 3
Enter the elements of matrix A:
1 2 3
4 5 6
7 8 9
Enter the elements of matrix B:
9 8 7
6 5 4
3 2 1
Resultant matrix is: (matrixA * matrixB)
30 24 18
84 69 54
138 114 90
Python Implementation:
Output:
Enter the value of N for N x N: 3
Enter the elements of matrix A:
1 2 3
4 5 6
7 8 9
Enter the elements of matrix B:
9 8 7
6 5 4
3 2 1
Resultant matrix is: (matrixA * matrixB)
30 24 18
84 69 54
138 114 90
Python Implementation:
matrixA = [] matrixB = [] print "Enter the value of N for N x N:" N = int(raw_input()) print "Enter the elements of matrix A:" for i in range(N): line = raw_input() list = map(int,line.split()) matrixA.append(list) print "Enter the elements of matrix B:" for i in range(N): matrixB.append(map(int,raw_input().split())) # multiply two matrices print "Resultant matrix is: (matrixA * matrixB)" for i in range(N): for j in range(N): sum = 0 for k in range(N): sum = sum + matrixA[i][k] * matrixB[k][j] print sum, print ""