+3 votes
in Class 11 by kratos

Write a program to input any two matrices and print product of matrices.

1 Answer

+1 vote
by kratos
 
Best answer

import random

m1 = input (“Enter number of rows in first matrix”)

n1 = input (“Enter number of columns in first matrix”)

a = [[random.random () for row in range (m1)] for col in range (n1)]

for i in range (m1):

for j in range (n1):

a[i][j] = input ()

m2 = input (“Enter the number of rows in the second matrix”)

n2 = input (“Enter the number of columns in the second matrix”)

b = [[random.random () for row in range (m2)] for cal in range (n2)]

for i in range (m2):

for j in range (n2):

b[i][j] = input ()

c = [[random.random () for row in range (ml)] for col in range (n2)]

if (n1 = = m2):

for i in range (m1):

for j in range (n2):

c[i][j] = 0 for kin range (n1):

c[i][j] + = a[i][k]*b[k][j]

print c[i][j], ‘\t’,

print

else:

print “Multiplication is not possible”

...