Answer to Question #238396 in Python for sai krishna

Question #238396

Write a program to print the anti-diagonal elements in the given matrix.

Input

The first line of input will contain an integer N, denoting the number of rows and columns of the input matrix.

The next N following lines will contain N space-separated integers, denoting the elements of each row of the matrix.

Output

The output should be a list containing the anti-diagonal elements.

Explanation

For example, if the given N is 3, and the given matrix is

1 2 3

4 5 6

7 8 9

The anti diagonal elements of the above matrix are 3, 5, 7. So the output should be the list

[3, 5, 7]

Sample Input 1

3

1 2 3

4 5 6

7 8 9

Sample Output 1

[3, 5, 7]

Sample Input 2

5

44 71 46 2 15

97 21 41 69 18

78 62 77 46 63

16 92 86 21 52

71 90 86 17 96

Sample Output 2

[15, 69, 77, 92, 71]


1
Expert's answer
2021-09-17T05:08:40-0400
n = int(input('N = '))
matrix = []
for i in range(n):
	matrix.append(list(map(int,input().split())))
anti_diag = []
for i in range(n):
	anti_diag.append(matrix[i][n-i-1])
print(anti_diag)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS