#include<stdio.h>
#defineM100
intmain()
{
inta[M][M],i,j,msum=0,ssum=0;
intN;
printf("inputN:");
scanf("%d",&N);
printf("請輸入%d*%d的矩陣:\n",N,N);
for(i=0;i<N;++i)
for(j=0;j<N;++j)
scanf("%d",&a[i][j]);
}
msum+=a[i][i];
ssum+=a[i][N-1-i];
printf("主對角線的和是:%d\n斜對角線的和是:%d\n\n",msum,ssum);
return0;
#include<stdio.h>
#defineM100
intmain()
{
inta[M][M],i,j,msum=0,ssum=0;
intN;
printf("inputN:");
scanf("%d",&N);
printf("請輸入%d*%d的矩陣:\n",N,N);
for(i=0;i<N;++i)
{
for(j=0;j<N;++j)
{
scanf("%d",&a[i][j]);
}
}
for(i=0;i<N;++i)
{
msum+=a[i][i];
ssum+=a[i][N-1-i];
}
printf("主對角線的和是:%d\n斜對角線的和是:%d\n\n",msum,ssum);
return0;
}