//Zhishen Lu Eating Steamed Bun v6
#include <stdio.h>
int main(void)
{
int monk[101],count=0,steabun=0,i;//Easy to count.monk[1]~monk[100] for the flower monk Zhishen Lu and other 99 monks,count to number off,steabun for the number of steamed buns already divided and i as a simple counter.
for (i=1;i<101;i++)
monk[i]=0;//Initialization of the array.Value 0 means they will participate in numbering off.
i=0;
while (steabun<99)
{
if (++i<=100&&!monk[i])//Make sure that the monk hasn't got a steamed bun yet
{
if (++count%5==0)
{
monk[i]=1;//Get a steamed bun
steabun++;
}
}
else if (i>100)
i=0;//Make sure to mumber off continuously
}
for(i=1;monk[i];i++) ;//Do you know why ";" exists?
printf("The position number of Zhishen Lu is %d.\n",i);
return 0;
}
Find any differences between the 6th version and the 5th one?
Right,we initialised monk[1] to monk[100] through a "for" circle in the latest version while not when defining the array.
But I learned from the textbook that an array could be defined and initialized like this:"int a[10]={0};"which means every array element equals 0.Then what's wrong with the 5th version?If interested,pay attention to my posts.
But I learned from the textbook that an array could be defined and initialized like this:"int a[10]={0};"which means every array element equals 0.Then what's wrong with the 5th version?If interested,pay attention to my posts.