c语言 5-12

1、

#include <stdio.h>

int main(void)
{
    int i, j, k, a[2][4][3], b[4][3] = {0};
    puts("please input the elements of the array.");
    for(i = 0; i < 2; i++)
    {
        for(j = 0; j < 4; j++)
        {
            for(k = 0; k < 3; k++)
            {
                printf("a[%d][%d][%d] = ", i, j, k); scanf("%d", &a[i][j][k]);
            }
        }
    }
    
    puts("\nshow the matrix form of the two examinations.");
    for(i = 0; i < 2; i++)
    {
        for(j = 0; j < 4; j++)
        {
            for(k = 0; k < 3; k++)
            {
                printf("%4d", a[i][j][k]);
            }
            putchar('\n');
        }
        puts("\n==============================================\n");
    }
    
    puts("\ncalculate the sum of two examinations.");
    for(i = 0; i < 4; i++)
    {
        for(j = 0; j < 3; j++)
        {
            for(k = 0; k < 2; k++)
            {
                b[i][j] += a[k][i][j];
            }
        }
    }
    for(i = 0; i < 4; i++)
    {
        for(j = 0; j < 3; j++)
        {
            printf("%4d", b[i][j]);
        }
        putchar('\n');
    }
    return 0;
}

 

posted @ 2021-05-03 15:15  小鲨鱼2018  阅读(35)  评论(0编辑  收藏  举报