#include <stdio.h>
int j = 0;
int judge(int sweet[])
{
int i;
for (i = 0; i < 10; i++)
{
if (sweet[0] != sweet[i]) return 1;
}
return 0;
}
void print(int sweet[])
{
int k;
printf(" %2d ", j++);
for (k = 0; k < 10; k++)
printf("%4d", sweet[k]);
printf("\n");
}
int main()
{
int sweet[10] = {10, 2, 8, 22, 16, 4, 10, 6, 14, 20}; //初始化数组数据
int i, j;
int sweet_;
printf("chi1d 1 2 3 4 5 6 7 8 9 10\n");
printf("..............................................\n");
printf("time\n");
print(sweet);
//左向右
while (judge(sweet))
{
sweet_ = sweet[0];
for (i = 0; i < 9; i++)
{
sweet[i] = sweet[i] / 2 + sweet[i + 1] / 2;
}
sweet[9] = sweet[9] / 2 + sweet_ / 2;
for (i = 0; i < 10; i++)
if (sweet[i] % 2 != 0) sweet[i]++;
print(sweet);
}
//右向左
//while (judge(sweet))
//{
// sweet_ = sweet[9];
// for (i = 9; i > 0; i--)
// {
// sweet[i] = sweet[i - 1] / 2 + sweet[i] / 2;
// }
// sweet[0] = sweet[0] / 2 + sweet_ / 2;
// for (i = 0; i < 10; i++)
// if (sweet[i] % 2 != 0) sweet[i]++;
// print(sweet);
//}
return 0;
}
![](https://img2023.cnblogs.com/blog/3168003/202304/3168003-20230426142959174-399329974.png)