描述:求一个3×3矩阵对角线元素之和
#include<iostream>
using namespace std;
int main()
{
int x,i,j,k,h,b,aa[3][3];
for (i = 0; i <=2; i++)
{
for (j = 0; j <= 2; j++)
{
cin >> x;
aa[i][j] = x;
}
}
int sum1,sum2;
sum1 = 0;
sum2 = 0;
for (k = 0; k <= 2;k++)
{
sum1 += aa[k][k];
}
for (h = 0; h <= 2; h++)
{
b = 2 - h;
sum2 += aa[h][b];
}
cout << sum1 << " " << sum2 << endl;
return 0;
}