addition of two matrices using python

 m=int(input("number of rows"))

n=int(input("number of coulns"))

a=[]

for i in range(m):

    row=[]

    for j in range(n):

        row.append(int(input()))

    a.append(row)

    

b=[]

for i in range(m):

    row=[]

    for j in range(n):

        row.append(int(input()))

    b.append(row)


res=[]

for i in range(m):

    row=[]

    for j in range(n):

        row.append(0)

    res.append(row)

for i in range(m):

    for j in range(n):

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

        

for i in range(m):

    for j in range(n):

        print(res[i][j],end=" ")

    print()

No comments:

Post a Comment