首页 > 游戏数码 > 电脑 > c语言之猜数游戏:[1]

c语言之猜数游戏:[1]

   来源:秒知站    阅读: 1.54W 次
字号:

用手机扫描二维码 在手机上继续观看

手机查看

当我们大家一起出去游玩或者聚会是会玩一种猜数字游戏

方法/步骤1

(01)写入所需头文件#include <stdlib.h>/*随机函数的申明*/#include <stdio.h> #include <time.h>

(02)所需变量的定义main(){int n,g,c=100,d=0,t;

(03)srand( (unsigned)time( NULL ) );n=rand()%100;    /*产生并调用随机数*/

c语言之猜数游戏:[1]

(04)程序其他部分printf("please input the number you guess between 0 to 100t");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 %dn",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 %dn",d,c) ;  scanf("%d",&t);g=t;} }if(g==n)printf("ttt|----------|nttt|you got it|nttt|----------|n");printf("nttt  Game overn");getch();}下如为运行结果

c语言之猜数游戏:[1] 第2张

特别提示

注意头文件的写入

电脑网络
IT技术
互联网
电脑
摄影
手机
游戏