0
Can this code be modified so that i can find the secondary diagonal elements ?
m=[[1,2,3],[4,5,6],[1,2,3]] sum=0 for i in range (3): for j in range (3): if i==j: sum=sum+m[i][j] print(sum)
1 Answer
+ 1
For a 3Ă3 matrix, the secondary diagonal is formed by these (i, j) pairs:
(0, 3)
(1, 2)
(2, 1)
(3, 0)
Do you see the relation? As i increases by 1, j decreases by 1. So maybe their sum is fixed? đ
Let me know if that doesn't make sense.