Your task is to write a program that reads a sequence of square matrices of integers, and for each one prints the sum of the numbers which are in their two diagonals.
Usign the definition
typedef vector<vector<int> > Matrix;
your program must implement and use the function
int sum_diagonals(const Matrix& mat);
that returns the sum of the numbers in the diagonals of the square matrix and non empty |mat|.
The input consists of a sequence of cases. Each case starts with the size of the matrix, followed by lines, each one with the integers of the corresponding row.
For each matrix, print a line with the sum of the numbers which are in its diagonals.
Author: Unknown
Translator: Carlos Molina
Generation: 2026-01-25T11:21:33.443Z
© Jutge.org, 2006–2026.
https://jutge.org