Given a MxN matrix,write a program to print all Anti-Diagonals elements of matrix
Input
The first line of input will contain a M, N values separated by space.
The second line will contain matrix A of dimensions MxN.
Output
The output should contain anti-diagonal elements separated by a line.
Explanation
For example, if M = 2, N = 3
Matrix A:
1 5 5
2 7 8
Output:
1
5 2
5 7
8
# used x and y instead of m,n
x, y = map(int, input().split())
#to find a matrix used code below
matrix = [list(map(int, input().split())) for _ in range(x)]
#used to find maximum sum
max_sum = x + y - 2
#for loop is used to find a matrix
for sum in range(max_sum+1):
for i in range(sum+1):
if i < x and sum - i < y:
print(matrix[i][sum - i], end=" ")
print()
Comments
Leave a comment