c语言中三维数组

 

001、

[root@PC1 test]# ls
test.c
[root@PC1 test]# cat test.c
#include <stdio.h>
int main(void)
{
        double tensu[2][4][3] = {{{3,4,2},{2,4,4},{2,4,3},{1,5,8}},{{4,4,2},{2,8,4},{2,8,9},{1,8,5}}};
        int i,j,k;
        for(i = 0; i < 2; i++)
        {
                for(j = 0; j < 4; j++)
                {
                        for(k = 0; k < 3; k++)
                        {
                                printf("tensu[%d][%d][%d] = %f\n", i, j, k, tensu[i][j][k]);
                        }
                }
        }
        return 0;
}
[root@PC1 test]# gcc test.c -o kkk
[root@PC1 test]# ls
kkk  test.c
[root@PC1 test]# ./kkk
tensu[0][0][0] = 3.000000
tensu[0][0][1] = 4.000000
tensu[0][0][2] = 2.000000
tensu[0][1][0] = 2.000000
tensu[0][1][1] = 4.000000
tensu[0][1][2] = 4.000000
tensu[0][2][0] = 2.000000
tensu[0][2][1] = 4.000000
tensu[0][2][2] = 3.000000
tensu[0][3][0] = 1.000000
tensu[0][3][1] = 5.000000
tensu[0][3][2] = 8.000000
tensu[1][0][0] = 4.000000
tensu[1][0][1] = 4.000000
tensu[1][0][2] = 2.000000
tensu[1][1][0] = 2.000000
tensu[1][1][1] = 8.000000
tensu[1][1][2] = 4.000000
tensu[1][2][0] = 2.000000
tensu[1][2][1] = 8.000000
tensu[1][2][2] = 9.000000
tensu[1][3][0] = 1.000000
tensu[1][3][1] = 8.000000
tensu[1][3][2] = 5.000000

 。

 

posted @ 2024-11-05 08:51  小鲨鱼2018  阅读(12)  评论(0编辑  收藏  举报