//猜数字
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a,x,y,n,b=0;
printf("请输入范围1~n中n的值:");
scanf("%d",&n);
a=rand()%n+1;
while(1)
{
printf("请输入一个整数:");
scanf("%d",&x);
if(x>a) printf("大了\n");
if(x<a) printf("小了\n");
b++;
if(x==a)
{
printf("恭喜你,猜对了\n");
printf("你猜对共用了%d次\n",b);
a=rand()%n+1;
printf("是否再来一局?(1.是 2.不是)\n");
scanf("%d",&y);
b=0;
if(y!=1) break;
}
}
}
标签:数字,int,scanf,C语言,小游戏,printf,include,输入
From: https://blog.csdn.net/hangweijie/article/details/136736641