#C396. Sum of Special Diagonal
Sum of Special Diagonal
Sum of Special Diagonal
You are given an n x n matrix. Your task is to calculate the sum of the elements along the special diagonal, which is the diagonal from the top-left corner to the bottom-right corner.
Formally, given a matrix \(A\) of size \(n \times n\), compute the value:
[ S = \sum_{i=0}^{n-1} A_{i,i} ]
Input will be provided from the standard input (stdin) and output should be printed to the standard output (stdout).
Note: The matrix is guaranteed to be square.
inputFormat
The input begins with an integer \(n\) representing the size of the matrix. The next \(n\) lines each contain \(n\) space-separated integers representing the rows of the matrix.
Example:
3 1 2 3 4 5 6 7 8 9
outputFormat
Output a single integer which is the sum of the elements on the special (main) diagonal.
For the sample input above, the output should be:
15## sample
3
1 2 3
4 5 6
7 8 9
15
</p>