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

 时间:2024-11-02 00:37:06

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]

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]
  • 食物语怎么自己使用存粮蒸兔包
  • 花生米都有什么作用功效?
  • windows系统查看硬件和设备信息
  • QQ飞车芭比传统双人舞蹈全P辅助最新 免费版
  • java使用Hutool获取指定日期的部分内容
  • 热门搜索
    手抄报的装饰花边 法律伴我行手抄报 关于热爱生命的手抄报 清明手抄报图片大全 清明节文明祭祀手抄报 防灾减灾一等奖手抄报 五年级手抄报 做文明小学生手抄报 安全手抄报版面设计图 民族团结手抄报花边