Answer to Question #184415 in Python for kamal

Question #184415

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

For example, if M = 4, N = 4

Matrix A:



4 4

1 2 3 4

5 6 7 8

9 10 11 12

13 14 15 16


So the output should be


1
Expert's answer
2021-04-22T13:15:07-0400
m, n = map(int, input().split())
matr = [list(map(int, input().split())) for i in range(m)]
for i in range(m):
    for j in range(n):
        print(matr[i][j],end=' ')
    print()
print()


for i in range(n):
    row = 0
    col = i
    while row < m and col > -1:
        #print('matr[{0}][{1}] = '.format(row, col), end='')
        print(matr[row][col])
        row += 1
        col -= 1
    print()
print()

for i in range(1,m):
    row = i
    col = n - 1
    while row < m and col > -1:
        #print('matr[{0}][{1}] = '.format(row, col), end='')
        print(matr[row][col])
        row += 1
        col -= 1
    print()    
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