Answer to Question #282273 in Python for Ch prasad

Question #282273




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

1
Expert's answer
2021-12-24T01:20:49-0500
# 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()

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