猜数字
计算机随机生成一个1-100之间的数,用户去猜计算机生成的数是哪个,直到猜对为止,并计算猜测次数。
```c
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
srand(time(0));
int number = rand()%100+1;
int count = 0;
int a = 0; //record the number you've input
printf("i have a number which between 1 and 100. ");
do{
printf("please guess the number: ");
scanf("%d",&a);
count++;
if(a>number){
printf("Your guess is high. ");
}else if(a<number){
printf("your guess is small. ");
}
}while(a!=number);
printf(" your guess is right! You guessed the right answer %d times",count);
return 0;
}