1、
#include <stdio.h>
int main(void)
{
int a[2][4][3] ={{{20,10,12},{30,20,10},{20,10,50},{20,10,30}},{{30,10,20},{40,30,10},{10,20,30},{50,10,20}}};
int sum[4][3] = {0};
int i, j, k;
for (i = 0; i < 4; i++)
{
for (j = 0; j < 3; j++)
{
for (k = 0; k < 2; k++)
{
sum[i][j] += a[k][i][j];
}
}
}
for (i = 0; i < 4; i++)
{
for (j = 0; j < 3; j++)
{
printf("%d ", sum[i][j]);
}
putchar('\n');
}
return 0;
}
↓
#include <stdio.h> int main(void) { int a[2][4][3] = {{{20,17,20},{30,10,32},{38,10,10},{80,30,10}},{{80,29,10},{20,30,30},{10,20,30},{38,20,10}}}; int i, j, k; int sum[4][3] = {0}; for (i = 0; i < 4; i++) { for (j = 0; j < 3; j++) { for (k = 0; k < 2; k++) { sum[i][j] += a[k][i][j]; } } } for (i = 0; i < 2; i++) { printf("%dst examination\n", i + 1); for (j = 0; j < 4; j++) { for (k = 0; k < 3; k++) { printf("%d ", a[i][j][k]); } putchar('\n'); } } puts("------\n------\n------"); puts("sum."); for (i = 0; i < 4; i++) { for (j = 0; j < 3; j++) { printf("%d ", sum[i][j]); } putchar('\n'); } return 0; }