Answer to Question #171358 in Python for sandeep

Question #171358

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.

Explanation


1
Expert's answer
2021-03-15T00:51:54-0400
A = [[1, 2, 3, 4],
     [5, 6, 7, 8],
     [9, 10, 11, 12],
     [13, 14, 15, 16]]


M = len(A)
N = len(A[0])
print("%d %d"%(M,N))
for col in range(N):
    scol = col
    srow = 0
    while(scol >= 0 and srow < N):
           print(A[srow][scol], end = " ")
           scol = scol-1
           srow = srow+1
    print("")
for row in range(1, N):
    srow = row
    scol = N - 1
    while(srow < N and scol >= 0):
          print(A[srow][scol],end=" ")
          scol = scol-1
          srow = srow+1
    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