我用一个一重循环实现的代码如下,非常简单!
#include <stdio.h>
#include <stdlib.h>
#define ROW 3
#define COL 4
int main(void)
{
int a[ROW][COL] = {1,2,3,4,5,6,7,8,9,10,11,12};
int sum = 0;
int i = 0;
for(i = 0; i < ROW*COL; ++i)
{
sum += a[i/COL][i%COL];
/*大家得稍微思考一下才可得知为什么, 呵呵*/
}
printf("sum = %d\n", sum);
system("PAUSE");
return 0;
}