given a mxn matrix write a program to print all anti-diagonal elements of matrix
m, n = input('Enter the values of M and N separated by a space: ').split()
m = int(m)
n = int(n)
matrix_str = input('Enter all matrix values separated by a space: ').split()
matrix = [matrix_str[n*i:n*(i+1)] for i in range(m)]
for i in range(n):
for j in range(i+1):
try:
print(matrix[j][i-j],end=' ')
except:
break
print('')
for i in range(1,m):
for j in range(i+1):
try:
print(matrix[i+j][-1-j],end=' ')
except:
break
print('')
Comments
Leave a comment