Friday, November 6, 2015

Funny C Program:Zhishen Lu Eating Steamed Bun v5

"If the two conditions of judgement mentioned in the previous version are combined together,will the problem be solved?"I asked myself.Then I tried to make it again and again.
The process was tough.You might notice that in the previous version,expressions in brackets are both in contrast to the right conditions to continuously number off.As I tried to put them together,using "&&" or "||" was a thorny problem.I tried many times,but still in vain.Eventually,I noticed that the right condition is very certain.Why not number off directly as the expression meets the condition?As to other cases,consider them expectly.
Here comes the 5th version of this program.

//Zhishen Lu Eating Steamed Bun v5
#include <stdio.h>
int main(void)
{
int monk[101]={0},count=0,steabun=0,i=0;//Easy to count.monk[1]~monk[100] for the flower monk Zhishen Lu and other 99 monks,value 0 means they will participate in numbering off.count to number off,steabun for the number of steamed buns already divided and i as a simple counter.
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;
}

How about this version?Seems perfect?No!
The screen showed nothing at all when running this program.
But I couldn't discover the errors by myself.I looked for help from a friend,and the problem was solved successfully.But it's not convictive enough,I thought.Want to know more about the next version?It's coming soon!

No comments:

Post a Comment