c语言之猜数游戏:[1]
1、 写入所需头文件
#include <stdlib.h>/*随机函数的申明*/#include <stdio.h> #include <time.h>
2、所需变量的定义
main(){int n,g,c=100,d=0,t;
3、 srand( (unsigned)time( NULL ) );n=rand()%100; /*产生并调用随机数*/
![c语言之猜数游戏:[1]](https://exp-picture.cdn.bcebos.com/2db6c1b2dc19ce2c8112b56a7fdca039121f11a2.jpg)
4、 程序其他部分
printf("please input the number you guess between 0 to 100\t");scanf("%d",&g);
while(g!=n){if(g<n) { d=g; printf("That was small,\n please guess it again and input a number between %d to %d\n",d,c); scanf("%d",&t);g=t;}if(g>n) {c=g; printf("That was large,\n please guess it again \ and input a number between %d to %d\n",d,c) ; scanf("%d",&t);g=t;} }if(g==n)printf("\t\t\t|----------|\n\t\t\t|you got it|\n\t\t\t|----------|\n");printf("\n\t\t\t Game over\n");getch();}
下如为运行结果
![c语言之猜数游戏:[1]](https://exp-picture.cdn.bcebos.com/d2987775f2c4ec99bd4aafb5c3fe1e425c6b07a2.jpg)
声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
阅读量:79
阅读量:188
阅读量:37
阅读量:70
阅读量:90