其他分享
首页 > 其他分享> > 猜数游戏,:猜0到100的数,直到猜对为止,得到随机数和猜数次数

猜数游戏,:猜0到100的数,直到猜对为止,得到随机数和猜数次数

作者:互联网

输入: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;
}

标签:guess,magic,猜数,counter,随机数,printf,100
来源: https://www.cnblogs.com/mtydd/p/14504344.html