Answer to Question #330322 in Python for cherry

Question #330322

write a program print of all anti diagonals element of matrix


1
Expert's answer
2022-04-18T15:19:49-0400






#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)

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