int main()
{
long i=5000,j=10000,m = 0;
char p,q = -1;
printf("请在心中想一个小于10000的数,想好了按任意键继续\n");
while('\n'!=getchar()){};
printf("电脑猜5000,小了按1,大了按2,相等按3\n");
scanf("%c",&p);
while('\n'!=getchar()){};
while(p=='1'||p=='2'||p=='3')
{
if(p=='1')
{
m = i;
i = (i+j)/2;
printf("电脑猜%d小了按1,大了按2,相等按3\n",i);
}
else if(p=='2')
{
j = i;
i = (i+m)/2;
printf("电脑猜%d小了按1,大了按2,相等按3\n",i);
}
else if('3'==p)
{
printf("恭喜电脑猜中了");
break;
}
scanf("%c",&p);
while('\n'!=getchar()){};
}
while('\n'!=getchar()){};
return 0;
}