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
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("")
Comments
Leave a comment