欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

重新设计标题: 探索C语言中的数字猜猜乐

最编程 2024-08-14 17:24:56
...
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
int main()
{
int x,num,st,ed;
char ch;
srand((int)time(NULL));
while(1)
{
printf("请输入你想要猜的数的范围(用空格隔开):");
scanf("%d %d",&st,&ed);
ed=ed-st+1;
num=rand()%ed+st;
printf("请输入你猜的数字:");
scanf("%d",&x);
while(x!=num)
{
if(x>num)
printf("猜大了,继续努力~~\n");
if(x<num)
printf("猜小了,继续加油哦!\n");
scanf("%d",&x);
}
printf("真棒!猜对了!!\n");
printf("继续玩请输入Y,否则请输入N\n");
getchar();
scanf("%c",&ch);
if(ch=='Y')
continue;
else
break;
}
return 0;

}