#include <iostream>
#include <time.h>
#include <cstdlib>
using namespace std;
int main() {
int n, s = 0, max = 0, min = 9;
srand(time(NULL));
do {
cout << "Input size of matrix: n = ";
cin >> n;
if (n < 0)
{
cout << "Input error! n < 0. Please try again" << endl;
continue;
}
else break;
} while (true);
int **matr = new int* [n];
for(int i = 0; i < n; i++)
matr[i] = new int [n];
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n;j++)
{
matr[i][j] = rand() % 10;
cout << matr[i][j] << " ";
}
cout << endl;
}
for (int i = 0; i < n; i++)
{
if (max < matr[i][i])
max = matr[i][i];
if (min > matr[i][n-i-1])
min = matr[i][n-i-1];
s += matr[i][i] + matr[i][n - i - 1];
}
if (n % 2 != 0)
s -= matr[n / 2][n / 2];
cout <<"Maximum number on the main diagonal: " << max << endl << "Minimum number on the secondary diagonal: " << min << endl << "Sum of numbers on the diagonals: " << s;
return 0;
}
/* Редактор не сохраняет отступы зачастую, поэтому прикрепил .cpp файл с кодом */