#include<stdio.h>
#include<stdlib.h>
int main(void)
{
int guess,magic,counter = 0;
int seed; //设置一个随机的种子
char reply; //记录用户的选择
printf("Please enter seed:\n");
scanf("%d",&seed);
srand(seed);
for(int i = 0;i<30;i++)
{
magic = rand()%100+1;
printf("%d ",magic);
if(i % 4 == 0)
putchar('\n');
}
putchar('\n');
do{
counter = 0;
magic = rand()%100+1;
do{
counter++;
printf("Please guess number:\n");
scanf("%d",&guess);
if(guess > magic){
printf("Wrong!Too big!\n");
}
else if(guess < magic){
printf("Wrong!Too small!\n");
}
else
{
printf("Right!\n");
}
}while(guess != magic && counter < 10); //限制猜的次数
printf("counter = %d\n",counter);
printf("Do you want to continue(y/n or Y/N)?");
scanf(" %c",&reply); //%c前有个空格 为了避免回车符读给reply
}while(reply == 'y' || reply == 'Y');
return 0;
}
[猜数字]c语言
于 2022-12-02 20:43:00 首次发布