Răspuns :
#include <iostream>
using namespace std;
int main() {
int n;
int a[100][100];
cout << "n=";
cin >> n;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
{
cout << "a[" << i << "][" << j << "]=";
cin >> a[i][j];
}
cout << "Matricea initiala:" << endl;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
cout << a[i][j] << " ";
cout << endl;
}
int suma=0;
int max = a[0][0];
for(int i=0; i<n; i++)
for(int j=0; j<n; j++)
if(i!=j)
suma=suma+a[i][j];
else
{
if(max<a[i][j])
max=a[i][j];
}
suma=suma+max;
cout<<"Suma="<<suma<<endl;
return 0;
}