当前位置:网站首页>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;
}
边栏推荐
- 【c语言】基础篇学习笔记
- L'avènement de l'ère 5G, une brève discussion sur la vie passée et présente des communications mobiles
- Wechat applet pull-down loading more waterfall flow loading
- 《动手学深度学习》(二)-- 多层感知机
- [untitled]
- 《西线无战事》我们才刚开始热爱生活,却不得不对一切开炮
- Go branch and loop
- Is the product of cancer prevention medical insurance safe?
- What is 5g industrial wireless gateway? What functions can 5g industrial wireless gateway achieve?
- Realizing deep learning framework from zero -- Introduction to neural network
猜你喜欢
【力扣刷题】15.三数之和(双指针);17.电话号码的字母组合(递归回溯)
Go语言介绍
First acquaintance with string+ simple usage (II)
Influence of air resistance on the trajectory of table tennis
Lei Jun wrote a blog when he was a programmer. It's awesome
[wireless image transmission] FPGA based simple wireless image transmission system Verilog development, matlab assisted verification
Realizing deep learning framework from zero -- Introduction to neural network
Déchirure à la main - tri
Finally got byte offer. The 25-year-old inexperienced perception of software testing is written to you who are still confused
[personal notes] PHP common functions - custom functions
随机推荐
Vite: scaffold assembly
Spring recruitment of Internet enterprises: Kwai meituan has expanded the most, and the annual salary of technical posts is up to nearly 400000
okcc为什么云呼叫中心比传统呼叫中心更好?
MySQL error: expression 1 of select list is not in group by claim and contains nonaggre
powershell_ View PowerShell function source code (environment variable / alias) / take function as parameter
Li Kou interview question 02.08 Loop detection
Is the product of cancer prevention medical insurance safe?
[source code analysis] NVIDIA hugectr, GPU version parameter server - (1)
First acquaintance with P4 language
Monkey test
Recyclerview add header
Introduction to JSON usage scenarios and precautions
The 11th Blue Bridge Cup single chip microcomputer provincial competition
Pandora IOT development board learning (RT thread) - Experiment 1 LED flashing experiment (learning notes)
regular expression
go 语言命名规范
MySQL advanced SQL statement 2
云服务器的安全设置常识
JVM knowledge points
Bitmap principle code record