猜数游戏,:猜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;
}

上一篇:pep/9伪代码


下一篇:leetcode (力扣) 869. 重新排序得到 2 的幂 (哈希表)