当前位置:首页 > 通信资讯 > 正文

本文实例为大家分享了C语言实现猜数字游戏的具体代码,供大家参考,具体内容如下

实现效果如图:

C语言实现猜数字游戏(c语言程序设计猜数字游戏)

代码如下:

?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 #include<stdio.h> #include<stdlib.h> #include<time.h> int main() { int Guess,Num; //Guess猜数,Num随机数 int Next; //下一次执行 do { system("cls"); //清屏 printf("-------------------------------------\n"); srand(time(NULL)); Num=rand()%100+1; //随机生成1-100数字 printf("请猜猜1-100内的数字:\n"); scanf("%d",&Guess); while(Guess!=Num) { //scanf用于继续猜数判断 if(Guess>Num) { printf("猜大啦.\n"); scanf("%d",&Guess); } if(Guess<Num) { printf("猜小啦.\n"); scanf("%d",&Guess); } } printf("恭喜你猜对啦!\n"); printf("想不想再猜一猜?Y/y或N/n\n"); getchar(); //输入是否继续执行字符y/n printf("-------------------------------------\n"); Next=getchar(); //赋值 }while(Next == 'Y' || Next == 'y'); //判断下次是否执行 printf("程序已退出...\n"); return 0; }

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。

原文链接:https://blog.csdn.net/weixin_53391957/article/details/113886352

如果您对该产品感兴趣,请填写办理(客服微信:xiaoxiongyidong)

为您推荐:

发表评论

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。