1.

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

Answer» import random

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

n1 = input (“Enter total number of columns in the 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 total number of rows in the second matrix”)

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

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

for i in range (m2):

for j in rnage (n2):

b [i][j] = input ()

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

if ((m1 = m2) and (n1 = = b)):

print “Output is”

for i in range (m1):

for j in range (n1)]

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

print c[i][j], ‘it’,

print

else :

print “Matrix addition is not possible”


Discussion

No Comment Found