这个小算法怎么写
比如一个二维数组
char table[3][8] ={ {1,2,3,4,5,6,7,8},
{9,10,11,12,13,14,15,16},
{17,18,19,20,21,22,23,24}
};
现在要把它打印成3*8行,每行的格式如:
第1行:1,2,3,4,5,6,7,8,9,10.........24
第2行:2,3,4,5,6,.......................24
第3行:3,4,5,6,7.........................24
依次类推
....
第24行:24
算法 二维数组
[解决办法]
#include <stdio.h>
int main()
{
int table[3][8] ={ {1,2,3,4,5,6,7,8},
{9,10,11,12,13,14,15,16},
{17,18,19,20,21,22,23,24}
};
for (int i = 0; i < 24; i++)
{
for (int j = i; j < 24; j++)
{
printf("%d", table[j / 8][j % 8]);
if (j != 23)
{
printf(", ");
}
}
printf("\n");
}
return 0;
}