int i,a[N][N];
int sum1 = 0,sum2 = 0;
for(i = 0; i < N; ++i) {
sum1 += a[i][i];
sum2 += a[i][N - 1- i];
}
cout << "主对角线之和:" << sum1 << endl;
cout << "次对角线之和:" << sum2 << endl;
#include
void main()
{
int m,n;
int i,j;
int sum1=0,sum2=0;
int a[100][100];
cout<<"请输入数组的行数和列数:"<
int n=m;
cout<<"请输入数组的各元素:"<
cin>>a[i][j];
if(i==j)
sum1=sum+a[i][j];//主对角线元素之和
if(i==n-1)
{
sum2=sum2+a[i][j];//次对角线元素之和
n--;
}
}
cout<<"主对角线元素之和为:"<
....................这是大一前半学期的练习题大哥,你自己慢慢画吧