#include <iostream> |
#include <iomanip> |
using namespace std; |
int main() |
{ |
int i ,j,m=0,n=0; |
int a[4][4]; |
int c[4][4]; |
//输入4*4矩阵 |
cout<< "请输入一个4*4矩阵:" <<endl; |
for (i=0;i<4;i++) |
{ |
for ( j=0;j<4;j++) |
{ |
cin>>a[i][j]; |
} |
} |
//输出4*4矩阵对角线元素之和 |
|
cout<< "两个4*4矩阵主对角线元素之和:" ; |
for (i=0;i<4;i++) |
{ |
m+=a[i][i]; |
|
} |
cout<<m<<endl; |
cout<< "两个4*4矩阵副对角线元素之和:" ; |
for (i=0;i<4;i++) |
{ |
for (j=0;j<=4;j++) |
{ |
if (i+j==3) |
{ |
n+=a[i][j]; |
} |
} |
}cout<<n<<endl; |
return 0; |
} |