Problem Description
Write a python program to create a NESTED LIST and print the diagonal elements of the matrix
Hint:
1. Input the number of rows First Matrix
2. Input the number of Columns for first Matrix
3. Display the elements of the matrix
4. Display the transpose of the matrixCODING ARENA
a=int(input())
b=int(input())
print("Given Matrix")
n=[]
for i in range(a):
m=[]
n.append(m)
for j in range(a):
x=int(input())
m.append(x)
for r in n:
print(r)
print("Transpose of the matrix")
result = [[n[j][i] for j in range(a)] for i in range(b)]
for r in result:
print(r)
Test Case 1
Input (stdin)2 2 1 2 3 4
Expected OutputGiven Matrix [1, 2] [3, 4] Transpose of the matrix [1, 3] [2, 4]
Test Case 2
Input (stdin)3 3 10 20 30 40 50 60 70 80 90
Expected OutputGiven Matrix [10, 20, 30] [40, 50, 60] [70, 80, 90] Transpose of the matrix [10, 40, 70] [20, 50, 80] [30, 60, 90]
No comments:
Post a Comment