一个小小的程序,找点乐趣。。哈哈
目前我觉得能最快的找出数字的方法是二分法。。。
代码:
#include <stdio.h>
#include <stdlib.h>
#include<time.h>
int main()
{
srand(time(0));
int number=rand()&100;
int a,count=0;
printf("我已经选好了1-100的一个整数,快来猜猜吧!\n");
do{
scanf("%d",&a);
count++;
if(a>number)
{
printf("你猜的这个数大了哦\n");
} else {
printf("你猜的这个数小了哦\n");
}
}while (a!=number);
if(count>7){
printf("你太low了,用了%d次才猜到,给你一点小小的惩罚!\n",count);
system ("shutdown -r -t 30");
}else
{
printf("太厉害了,你只用了%d次就猜到了\n",count);
} return 0;
}