write a program print of all anti diagonals element of matrix
#Implement function to print All anti diagonal element in square #matrix
def AntiDiagonal(mat) :
n=len(mat)
N = 2 * n - 1
ans = []
for i in range(N) :
ans.append([])
# Push anti diagonal element
for i in range(n) :
for j in range(n) :
ans[i + j].append(mat[i][j])
# print pushed element
for i in range(len(ans)) :
for j in range(len(ans[i])) :
print(ans[i][j] , end = " ")
print()
n=int(input('Enter a size square matrix: '))
mat=[]
for i in range(n):
line=list(map(int,input().split()))
mat.append(line)
print('=================Anti Diagonal Elements=================')
AntiDiagonal(mat)
Comments
Leave a comment