第1个回答 2011-03-05
#include <stdio.h>
int main()
{
int arr[10][10]=
{
{82,25,29,89,100,13,52,70,10,35},
{84,75,41,17,18,87,40,48,57,38},
{81,93,53,24,86,26,85,39,03,15},
{33,76,9,54,16,14,61,59,92,91},
{45,64,01,78,19,99,22,60,43,74},
{67,63,96,47,12,20,27,42,73,58},
{05,66,55,11,97,49,98,62,30,32},
{8,34,90,83,46,68,56,04,95,21},
{6,7,80,37,88,79,28,77,31,72},
{94,2,51,65,23,50,36,44,71,69},
};
int i=0;
int j=0;
int crossValue1=0;
int crossValue2=0;
for(i=0; i<10; i++)
{
int rowValue=0;
int colValue=0;
for(j=0; j<10; j++)
{
rowValue += arr[i][j];
colValue += arr[j][i];
if(i==j)
crossValue1 += arr[i][j];
if(i+j==9)
crossValue2 += arr[i][j];
}
printf("第%d行:\t\t%d\n",i+1,rowValue);
printf("第%d列:\t\t%d\n",i+1,colValue);
}
printf("左上右下:\t%d\n",crossValue1);
printf("左下右上:\t%d\n",crossValue2);
return 0;
}
输出效果:
第1行: 505
第1列: 505
第2行: 505
第2列: 505
第3行: 505
第3列: 505
第4行: 505
第4列: 505
第5行: 505
第5列: 505
第6行: 505
第6列: 505
第7行: 505
第7列: 505
第8行: 505
第8列: 505
第9行: 505
第9列: 505
第10行: 505
第10列: 505
左上右下: 505
左下右上: 505
毕业后从事网站开发,已经好久没写C的代码了,呵呵,不知道是不是你要的效果