输入:0到100的数 输出:随机数和猜数次数
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
int magic,guess, counter;
srand(time(NULL));
magic = rand()%100 +1;
counter =0;
do{printf("input a number:\n");
scanf("%d",&guess);
counter++;
if(guess <magic)
printf("wrong,low\n");
else if(guess> magic)
printf("wrong, high\n");
else
printf("right,\n");
}while(guess != magic);
printf("counter =%d \n",counter);
return 0;
}