Given a MxN matrix,write a program to print all Anti-Diagonals elements of matrix
M, N = map(int, input().split())
if M != N:
print('Diagonal does not exist')
exit()
matrix = []
for i in range(M):
line = list(map(int, input().split()))
matrix.append(line)
matrix = matrix[::-1]
anti_diagonal_elements = []
for i, el in enumerate(matrix):
anti_diagonal_elements.append(el[i])
print('Answer:', *anti_diagonal_elements)
Comments
Leave a comment