Problem Description
Write a program to display the diagonal elementsCODING ARENA
a=int(input())
b=int(input())
mat=[]
for i in range(a):
n=[]
mat.append(n)
for j in range(b):
z=int(input())
n.append(z)
print("The List")
print(mat)
print("The Array elements")
for i in range(a):
for j in range(b):
print(mat[i][j],end=" ")
print()
print("The Diagonal elements")
for i in range(a):
print(mat[i][i])
Test Case 1
Input (stdin)3 3 1 2 3 4 5 6 7 8 9
Expected OutputThe List [[1, 2, 3], [4, 5, 6], [7, 8, 9]] The Array elements 1 2 3 4 5 6 7 8 9 The Diagonal elements 1 5 9
Test Case 2
Input (stdin)2 2 10 20 30 40
Expected OutputThe List [[10, 20], [30, 40]] The Array elements 10 20 30 40 The Diagonal elements 10 40
No comments:
Post a Comment