Addition of Diagonal Elements in Matrix


Output

Explanation :

Considering above 3×3 matrix -

  1. We have to add a[0][0],a[1][1],a[2][2]
  2. By Observing , it is clear that when i = j Condition is true then and then only we have to add the elements