#K86037. Diagonal Sum of a Square Matrix
Diagonal Sum of a Square Matrix
Diagonal Sum of a Square Matrix
In this problem, you are given a square matrix of size (n \times n). Your task is to compute the sum of the elements on the main diagonal, i.e. the elements (a_{ii}) for (1 \leq i \leq n).
The input is read from standard input and the output should be printed to standard output. For example, given the matrix [[2, 5], [3, 7]]
, the diagonal sum is (2 + 7 = 9).
inputFormat
The first line contains an integer (n), the size of the matrix. The following (n) lines each contain (n) space-separated integers representing the elements of the matrix.
outputFormat
Output a single integer representing the sum of the diagonal elements of the matrix.## sample
2
2 5
3 7
9