请问这么写可以吗?
#include <stdio.h>
int main()
{
int arr[3][3] = {{1,2,3},{4,5,6},{7,8,9}};
int i,j;
int sum=0;
for(i=0;i<3;i++)
{
j=i;
sum=sum+arr[j][j];
}
printf("对角线元素之和是:%d\n",sum);
return 0;
}
#include <stdio.h>
int main()
{
int arr[3][3] = {{1,2,3},{4,5,6},{7,8,9}};
int i,j;
int sum=0;
for(i=0;i<3;i++)
{
j=i;
sum=sum+arr[j][j];
}
printf("对角线元素之和是:%d\n",sum);
return 0;
}
2016-01-24
举报