c语言编写猜数小游戏
来源:互联网 发布:java发送邮件的代码 编辑:程序博客网 时间:2024/04/30 13:57
#define _CRT_SECURE_NO_WARNINGS 1#include "stdio.h"#include <stdlib.h>#include <time.h>void menu(){<span style="white-space:pre"></span>printf("***************************************\n");<span style="white-space:pre"></span>printf("****************1.play*****************\n");<span style="white-space:pre"></span>printf("****************0.exit*****************\n");<span style="white-space:pre"></span>printf("***************************************\n");}void play_game(){<span style="white-space:pre"></span>int num = rand() % 100 + 1;//给出一个随机数<span style="white-space:pre"></span>int i = 0;<span style="white-space:pre"></span>while (1)<span style="white-space:pre"></span>{<span style="white-space:pre"></span>printf("请猜数> ");<span style="white-space:pre"></span>scanf("%d", &i);<span style="white-space:pre"></span>if (i > num)<span style="white-space:pre"></span>printf("猜大了\n\n");<span style="white-space:pre"></span>else if (i < num)<span style="white-space:pre"></span>printf("猜小了\n\n");<span style="white-space:pre"></span>else<span style="white-space:pre"></span>{<span style="white-space:pre"></span>printf("猜对了\n");<span style="white-space:pre"></span>break;<span style="white-space:pre"></span>}<span style="white-space:pre"></span>}}int main(){<span style="white-space:pre"></span>int choice = 1;<span style="white-space:pre"></span>srand((unsigned)time(NULL));<span style="white-space:pre"></span><span style="white-space:pre"></span>while (choice)<span style="white-space:pre"></span>{<span style="white-space:pre"></span>menu();//打印菜单<span style="white-space:pre"></span>printf("请选择> ");<span style="white-space:pre"></span>scanf("%d", &choice);<span style="white-space:pre"></span>printf("\n");<span style="white-space:pre"></span>switch (choice)<span style="white-space:pre"></span>{<span style="white-space:pre"></span>case 1:play_game();<span style="white-space:pre"></span>break;<span style="white-space:pre"></span>case 0:<span style="white-space:pre"></span>break;<span style="white-space:pre"></span>}<span style="white-space:pre"></span>}<span style="white-space:pre"></span>system("pause");<span style="white-space:pre"></span>return 0;}
0 0
- c语言编写猜数小游戏
- c语言:编写猜数字小游戏。
- C语言编写猜数字小游戏
- C语言编写猜字小游戏
- 用c语言编写猜数字小游戏
- c语言编写的小游戏
- C语言编写扫雷小游戏
- C语言递归调用2:猜数小游戏
- 用c语言编写小游戏:贪吃蛇
- 用c语言编写三子棋小游戏
- c语言猜数字小游戏
- C语言猜数字小游戏
- 【C语言】猜数字小游戏
- C语言小游戏:猜数字
- 以前用C语言编写的生成随机数的猜数字小游戏
- 用C语言编写的 俄罗斯方块小游戏(tetris game)
- C语言编写小游戏——骑士飞行棋
- Objective-C语言编写(OC)打僵尸小游戏源码
- Android版本更新
- MYSQl的学习笔记------表的基本操作
- Java:JVM内存管理(一)
- JavaScript DOM操作
- 【Consul】多数据中心
- c语言编写猜数小游戏
- HTML标签的嵌套
- Android中线程通讯类Handler
- Android开发之手把手教你写ButterKnife框架(一)
- jQuery 循环遍历对象/集合/数组
- RecyclerView分割线——万能分割线
- Jquery的选择器
- 去除.DS_Store
- 人脸检测——Faster R-CNN