用C语言编写一个猜数字游戏的程序(最好能够解释一下)

核心提示已经改正,如下:#include<stdio.h>#include<stdlib.h>#include<time.h>void circle(int i){ int n ; printf("请输入您所猜的数字(0-100) \n");

已经改正,如下:

#include<stdio.h>

#include<stdlib.h>

#include<time.h>

void circle(int i)

{

int n ;

printf("请输入您所猜的数字(0-100) n");

scanf("%d",&n);

if(i<n)

{

printf("the number is larger,input agine.n");

circle(i);

}

if(i>n)

{

printf("the number is smaller.input agine n");

circle(i);

}

if(i==n)//?不是

printf("the number is %d so congratulations!you got it!",i);

}

int main()

{

int flag =1;

printf("This is a small game,what you should do is just guess a intange number.n");

printf("Now,please guess the number!n");

srand((unsigned)time(NULL));

while(flag)

{

int i=rand()%100;//?使用 % 而不是 / ,产生的数字在0-100之间,放在循环体内,每次循环都产生一个随机数

circle(i);

printf("n继续玩请输入 1,退出请输入 0");

scanf("%d",&flag);

}

getchar();

return 0;

}

 
友情链接
鄂ICP备19019357号-22