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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM