23根火柴游戏

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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Love 6

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值