C语言猜数
# include <stdio.h>
# include <stdlib.h>
# include <time.h>
int main()
{
int a,n=0,b;
srand(time(0));
a=rand()%100;
printf("这是一个猜数游戏\n");
printf("你要输入一个100以内正整数\n");
scanf("%d",&b);
do
{
n++;
if (b==a)
{
if(n<=3)
{
printf("\ncongratulation you,you are so luky.\n");
printf("you guess it %d and you guessed it. \n",n);
}
else
printf("真遗憾,你猜了%d次才猜中\n",n);
break;
}
else if (b>a)
printf("大了\n");
else
printf("小了\n");
printf("加油,你要继续输入一个正整数\n");
scanf("%d",&b);
}
while(b>0);
if(b<=0)
printf("这个数要大于等于0\n");
system("color 0A");
return 0;
}
|