Anti-Diagonals
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.
m, n = map(int, input().split())
matrix = [list(map(int, input().split())) for _ in range(m)]
max_sum = m + n - 2
for sum in range(max_sum+1):
for i in range(sum+1):
if i < m and sum - i < n:
print(matrix[i][sum - i], end=" ")
print()
Comments
Leave a comment