Answer to Question #166350 in Python for hemanth

Question #166350

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.




1
Expert's answer
2021-02-25T11:45:26-0500
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()

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