/**//*
*在1到100的范围内输入一个数,电脑就会玩猜数字游戏了
*/
#include<stdlib.h>
#include<stdio.h>
#include<time.h>
#define getrandom( min, max ) ((rand() % (int)(((max) + 1) - (min))) + (min))
void main()
{
int num,num1,num2,num3;
srand((int)time(NULL));
printf("please int a num from 1~100:");
scanf("%d",&num);
num1=1;
num2=100;
while(1)
{
num3=getrandom(num1,num2);
if(num==num3)
{
printf("\n\nAHA!!You are right!\n");
printf("The number is %d\n",num);
break;
}
else if(num<num3)
{
printf("your number %d is bigger than the answer!\n",num3);
printf("please input another num(%d - %d):\n",num1,num3-1);
num2=num3-1;
}
else if(num>num3)
{
printf("your number %d is smaller than the answer!\n",num3);
printf("please input another num(%d - %d):\n",num3+1,num2);
num1=num3+1;
}
}
}