Support our Blind Hand Charity by donating at 9818291723. Your contribution has the potential to bring about significant positive change for humanity.

Search This Blog

Sunday, August 13, 2023

SUM OF EACH ROW AND COLUMN OF A MATRIX

r=int(input("Enter number of rows = "))
c=int(input("Enter number of columns = "))
l=[[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]]
t=[]
m=[]
k=[]
for i in range(0,c):
    for j in range(0,r):
        x=int(input("Enter the element = "))
        l[i][j]=x
        
for i in range(0,c):
    s=0
    m=0
    for j in range(0,r):
        s+=l[i][j]
        m+=l[j][i]
    k.append(s)
    t.append(m)

for i in range(0,r):
    for j in range(0,c):
        print(l[i][j],end=',')
        if j==c-1:
            print('--->',end='')
    if j==c-1:
        print(k[i])

for i in range(-r,r):
    if i>=0:
        print(t[i],end='')
    else:
        print('| '*3)

OUTPUT