当前位置:网站首页>C语言猜数字游戏
C语言猜数字游戏
2022-07-02 04:08:00 【开飞机的贝塔儿】
猜数字游戏(1-100)
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
void menu()
{
printf("###########################\n");
printf("######1.play 0.exit######\n");
printf("###########################\n");
}
void game()
{
int ret;
int guess;
ret=rand() % 100 + 1; //生成随机数1-100
while (1)
{
printf("猜数->");
scanf("%d", &guess);
if (guess > ret)
printf("猜大了\n");
else if (guess < ret)
printf("猜小了\n");
else
{
printf("正确\n");
break;
}
}
}
int main()
{
int input;
do
{
srand((unsigned int)time(NULL)); //时间戳,随机起点的设计
menu();
printf("是否游戏:");
scanf("%d",&input);
switch (input)
{
case 1:
game();
break;
case 0:
printf("退出游戏!!!\n");
break;
default:
printf("输入有误,重新输入:\n");
break;
}
} while (input);
return 0;
}
边栏推荐
- 66.qt quick-qml自定义日历组件(支持竖屏和横屏)
- Opencv learning example code 3.2.4 LUT
- Set vscode. When double clicking, the selected string includes the $symbol - convenient for PHP operation
- [personnel density detection] matlab simulation of personnel density detection based on morphological processing and GRNN network
- LxC limits the number of CPUs
- 《西线无战事》我们才刚开始热爱生活,却不得不对一切开炮
- Fingertips life Chapter 4 modules and packages
- Installation et utilisation du lac bleu
- MySQL error: expression 1 of select list is not in group by claim and contains nonaggre
- How should the team choose the feature branch development mode or trunk development mode?
猜你喜欢
【小技巧】使用matlab GUI以对话框模式读取文件
Microsoft Research Institute's new book "Fundamentals of data science", 479 Pages pdf
How should the team choose the feature branch development mode or trunk development mode?
[personnel density detection] matlab simulation of personnel density detection based on morphological processing and GRNN network
The first game of the 11th provincial single chip microcomputer competition of the Blue Bridge Cup
【leetcode】34. Find the first and last positions of elements in a sorted array
藍湖的安裝及使用
The second game of the 12th provincial single chip microcomputer competition of the Blue Bridge Cup
JVM知识点
文档声明与字符编码
随机推荐
Pandora IOT development board learning (RT thread) - Experiment 1 LED flashing experiment (learning notes)
go 语言命名规范
2022-07-01: at the annual meeting of a company, everyone is going to play a game of giving bonuses. There are a total of N employees. Each employee has construction points and trouble points. They nee
5g era is coming in an all-round way, talking about the past and present life of mobile communication
The confusion I encountered when learning stm32
微信小程序 - 实现获取手机验证码倒计时 60 秒(手机号+验证码登录功能)
Analysis of the overall design principle of Nacos configuration center (persistence, clustering, information synchronization)
Qt插件之Qt Designer插件实现
How to solve the code error when storing array data into the database
Yolov5网络修改教程(将backbone修改为EfficientNet、MobileNet3、RegNet等)
Spring moves are coming. Watch the gods fight
Target free or target specific: a simple and effective zero sample position detection comparative learning method
MySQL error: expression 1 of select list is not in group by claim and contains nonaggre
手撕——排序
cookie、session、tooken
Basic operations of MySQL database (based on tables)
go 变量与常量
Lost a few hairs, and finally learned - graph traversal -dfs and BFS
The difference between vectorresize and reverse.
Sorted out an ECS summer money saving secret, this time @ old users come and take it away