Check The Programming Section
Consider the following example:
1 2 3
4 5 6
7 8 9
The Sum of principal diagonal elements = 1 + 5 + 9 = 15
The Sum of secondary diagonal elements = 3 + 5 + 7 =15
Consider a square matrix of size 3
A[0,0] A[0,1] A[0,2]
A[1,0] A[1,1] A[1,2]
A[2,0] A[2,1] A[2,2]
Sum of principal diagonal elements are = A[0,0] + A[1,1] + A[2,2]
Su of secondary diagonal elements are = A[0,2] + A[1,1] + A[2,0]