C语言基础:遍历输出三维数组
#include <stdio.h> int main(void) { int row, column, table; float values[2][3][5] = { {{1.0, 2.0, 3.0, 4.0, 5.0}, {6.0, 7.0, 8.0, 9.0, 10.0}, {11.0, 12.0, 13.0, 14.0, 15.0}}, {{16.0, 17.0, 18.0, 19.0, 20.0}, {21.0, 22.0, 23.0, 24.0, 25.0}, {26.0, 27.0, 28.0, 29.0, 30.0}} }; for (row = 0; row < 2; row++) for (column = 0; column < 3; column++) for (table = 0; table < 5; table++) printf("values[%d][%d][%d] = %f\n", row, column, table, values[row][column][table]); return 1; }
输出结果
values[0][0][0] = 1.000000 values[0][0][1] = 2.000000 values[0][0][2] = 3.000000 values[0][0][3] = 4.000000 values[0][0][4] = 5.000000 values[0][1][0] = 6.000000 values[0][1][1] = 7.000000 values[0][1][2] = 8.000000 values[0][1][3] = 9.000000 values[0][1][4] = 10.000000 values[0][2][0] = 11.000000 values[0][2][1] = 12.000000 values[0][2][2] = 13.000000 values[0][2][3] = 14.000000 values[0][2][4] = 15.000000 values[1][0][0] = 16.000000 values[1][0][1] = 17.000000 values[1][0][2] = 18.000000 values[1][0][3] = 19.000000 values[1][0][4] = 20.000000 values[1][1][0] = 21.000000 values[1][1][1] = 22.000000 values[1][1][2] = 23.000000 values[1][1][3] = 24.000000 values[1][1][4] = 25.000000 values[1][2][0] = 26.000000 values[1][2][1] = 27.000000 values[1][2][2] = 28.000000 values[1][2][3] = 29.000000 values[1][2][4] = 30.000000