计算5×6数组中所有数之和
1个回答
展开全部
#include<stdio.h>
#define N 5
void main() { int i,j,a[N][N],sum1,sum2;
for ( i=0;i<N;i++ ) for ( j=0;j<N;j++ ) scanf("%d",a[i][j]);
sum1=sum2=0; for ( i=0;i<N;i++ ) { sum1+=a[i][i]; sum2+=a[i][N-i-1]; }
printf("正对角线元素和%d,反对角线元素和%d\n",sum1,sum2);
}
#define N 5
void main() { int i,j,a[N][N],sum1,sum2;
for ( i=0;i<N;i++ ) for ( j=0;j<N;j++ ) scanf("%d",a[i][j]);
sum1=sum2=0; for ( i=0;i<N;i++ ) { sum1+=a[i][i]; sum2+=a[i][N-i-1]; }
printf("正对角线元素和%d,反对角线元素和%d\n",sum1,sum2);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询