#P1465. 矩阵对角线元素之和(完善程序)
矩阵对角线元素之和(完善程序)
Description
#include <iostream>
using namespace std;
const int N=3;
int main()
{
int i,j,sum1,sum2;
int a[N][N];
for(i=0;i<N;i++)
{
for(j=0;j<N;j++)
{
cin>>a[i][j];
}
}
sum1=0;
_____(1)______
for(i=0;i<N;i++)
{
for(j=0;j<N;j++)
{
if(____(2)____) sum1+=a[i][j];
if(____(3)____) sum2+=a[i][j];
}
}
cout<<sum1<<" "<<sum2;
return 0;
}
Input Format
矩阵Output Format
主对角线的元素和 副对角线的元素和1 2 3
1 1 1
3 2 13 7