Răspuns:
#include <iostream>
using namespace std;
int n,i,j,a[20][20],s=0,s2=0;
int main()
{
cout<<"n=";cin>>n;
cout<<"Introduce matricea:"<<endl;
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
{
cin>>a[i][j];
}
for(i=1;i<=n;i++)
s=s+a[i][n-i+1]*a[i][n-i+1];
for(i=1;i<=n;i++)
s2=s2+a[i][i];
cout<<"Suma elementelor diagonalei principale este:"<<s2<<endl;
cout<<"Suma patratelor elementelor diagonalei secundare este:"<<s<<endl;
return 0;
}
Explicație: