Answer to Question #165141 in Python for raj

Question #165141

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-02-22T16:07:09-0500
#!/usr/bin/env python

# read matrix dimentions
l = input().split()
m = int(l[0])
n = int(l[1])

# read a matrix
A = []
for i in range(m):
    row = []
    l = input().split()
    for j in range(n):
        row.append(float(l[j]))
    A.append(row)

# print antidiagonal
j = n-1
for i in range(m):
    print(A[i][j])
    j -= 1
    if j < 0:
        break
           

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