求3行3列矩阵a[3][3]={1,2,3,4,5,6,7,8,9}非对角线上元素之和。
程序员文章站
2022-03-08 15:55:11
...
#include <stdio.h>
int main()
{
int a[3][3]={1,2,3,4,5,6,7,8,9,};
int b[3];
int sum=0;
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
if(i==j)
{continue;}
else
{sum+=a[i][j];}
}
}
printf("%d\n",sum);
return 0;
}