#include
#include
using namespace std;
int main()
{
int a[4][4] =//初始化题目给予的数组
{
8,10,-5,7,
3,-2,9,6,
3,4,6,19,
4,2,-7,3
};
int n = 0,m = 0;//分别记录主与次对角线只和。
int i,j;
for(i=0;i<4;i++)
n += a[i][i];
for(i=0;i<4;i++)
m += a[i][3-i];
cout<int N = 0;//用来记录最后一小题的结果
for(i=0;i<4;i++)
{
for(j=i;j<4;j++)
N += a[i][j];
}
cout<return 0;
}
//PS:敢不敢再简单一点?
//#include "stdafx.h"//vc++6.0加上这一行.
#include
using namespace std;
int main(void){
int m[4][4]={{8,10,-5,7},{3,-2,9,6},{3,4,6,19},{4,2,-7,3}};
for(int sum=0,md=0,dd=0,i=0;i<4;i++){
md+=m[i][i];
dd+=m[i][3-i];
for(int j=i;j<4;sum+=m[i][j++]);
}
cout << "The main diagonal: " << md << endl;
cout << "The deputy diagonal: " << dd << endl;
cout << "The sum of these numbers: " << sum << endl;
return 0;
}