本文共 1116 字,大约阅读时间需要 3 分钟。
下面是一个模拟过程:
注意!游戏开始了。。。。。。 火柴还剩下21根*** 请输入你要取的火柴数目:* 3 计算机拿取的火柴数是:2 火柴还剩下16根*** 请输入你要取的火柴数目:* 2 计算机拿取的火柴数是:3 火柴还剩下11根*** 请输入你要取的火柴数目:* 5 请遵守游戏规则,你拿取的火柴数目有问题!请重新拿取! 火柴还剩下11根*** 请输入你要取的火柴数目:* 2 计算机拿取的火柴数是:3 火柴还剩下6根*** 请输入你要取的火柴数目:* 3 计算机拿取的火柴数是:2 火柴还剩下1根*** 请输入你要取的火柴数目:* 1 计算机赢了!游戏结束!#includeint main() { int computer, people, spare = 21; printf("注意!游戏开始了。。。。。。\n"); while (1) { printf("*******火柴还剩下%d根**********\n", spare); printf("*******请输入你要取的火柴数目:********\n"); scanf("%d", &people); if (people < 1 || people > 4 || people > spare) { printf("请遵守游戏规则,你拿取的火柴数目有问题!请重新拿取!\n\n"); continue; } spare -= people; if (spare == 0) { printf("计算机赢了!游戏结束!\n"); break; } computer = 5 - people; spare -= computer; printf("计算机拿取的火柴数是:%d\n", computer); if (spare == 0) { printf("计算机赢了!游戏结束!\n"); break; } } return 0;}
转载地址:http://ojnlf.baihongyu.com/