Mooc课后习题集 及 做到的一些有趣的题
这是我初学c开始有意识的记录自己做的每一道题开始写下的代码水平 一个一个代码发出来 直到我现在学的数据结构 那个时候还不会注释 格式什么的也是按照自己怎么喜欢怎么来 如果真不会看会代码理解一下 qwq 如代码有错请见谅 毕竟都好久以前敲得了hhh ~~
如果对各位的思路引导有帮助那更好
#include <stdio.h>
int main()
{
int i=23,n,computertemp;
printf("Game start!\n");
printf("Note: the maximum number is 3\n");
do
{
printf("Please enter the number of matches you are moving:\n");
scanf("%d",&n);
i-=n;
if(n>3 || n<=0 || i<0)
{
printf("The number you entered is wrong£¬please re-enter!\n");
i+=n;
}
else
{
printf("The number of matches you are moving is %d:\n",n);
printf("The number of matches left is: %d\n",i);
if(i==3)
{
printf("The number of matches that have been moved by the computer is: %d\n",2);
i-=2;
printf("The number of matches left is:%d\n",1);
}
else if(i==2 ||i==1)
{
printf("The number of matches that have been moved by the computer is: %d\n",1);
printf("The number of matches left is:%d\n",--i);
}
if(i==0)
printf("Congratulations£¡You won!\n");
else
{
computertemp=i%3+1;
printf("The number of matches that have been moved by the computer is: %d\n",computertemp);
i-=computertemp;
printf("The number of matches left is:%d\n",i);
}
fflush(stdin);
}
}while(i>0);
return 0;
}