Problem Description
Write a python program to create a NESTED LIST and print the sum of the diagonal elements in the matrix
Hint:
1. Input the number of rows First Matrix
2. Input the number of Columns for Second Matrix
3. Display the sum of the diagonal elements in the matrixCODING ARENA
a=int(input())
b=int(input())
x=[]
count=0
for i in range(a):
n=[]
x.append(n)
for j in range(b):
m=int(input())
n.append(m)
for i in range(a):
for j in range(b):
if(i==j):
count+=x[i][j]
print(count)
Test Case 1
Input (stdin)2 2 10 20 30 40
Expected Output50
Test Case 2
Input (stdin)3 3 10 20 30 40 50 60 70 80 90
Expected Output150
No comments:
Post a Comment