当前位置:网站首页>[C language] guessing numbers game [function]
[C language] guessing numbers game [function]
2022-07-28 20:03:00 【An ran_】
One 、 Thought analysis
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-svd47f8S-1651421074624)(C:\Users\19271\AppData\Roaming\Typora\typora-user-images\image-20220501234359803.png)]](/img/bd/78812c715c4c1610dcff329cafa4ab.png)
Two 、 Code demonstration
// Guess the number
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
void menu()
{
printf("**********************\n");
printf("**** 1. Start the game ****\n");
printf("**** 2. Quit the game ****\n");
printf("**********************\n");
}
void game()
{
int ret = rand() % 100 + 1;// The random number is 1~100 Between
int guess;
while (1)
{
printf(" Please enter a number :>");
scanf("%d", &guess);
if (guess == ret)
{
printf(" congratulations ! Guessed it !\n");
break;
}
else if (guess > ret)
{
printf(" Guess big \n");
}
else
{
printf(" Guess small \n");
}
}
}
int main()
{
srand((unsigned int)time(NULL));
int input;
do
{
menu();
printf(" Please select :>");
scanf("%d", &input);
switch (input)
{
case 1:
printf(" Start the game \n");
game();
break;
case 0:
printf(" Quit the game \n");
break;
default:
printf(" Wrong choice , Please re-enter \n");
break;
}
} while (input);
return 0;
}
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-6K3FfXX6-1651421074627)(C:\Users\19271\AppData\Roaming\Typora\typora-user-images\image-20220502000123665.png)]](/img/db/8ebdb02f137878224367503b730803.png)
边栏推荐
- Know small and medium LAN WLAN
- 云计算笔记part.2——应用管理
- 基于C语言的信息管理系统和小游戏
- leetcode day1 分数排名
- English Translation Spanish - batch English Translation Spanish tools free of charge
- Longest Palindromic Substring
- 你知道雨的类型有几种?
- 云计算笔记part.1——系统管理
- Special draft of Mir | common sense knowledge and reasoning: representation, acquisition and application (deadline on October 31)
- 【微信小程序开发】页面导航与传参
猜你喜欢

一文读懂如何部署具有外部数据库的高可用 K3s

Read how to deploy highly available k3s with external database

KubeEdge发布云原生边缘计算威胁模型及安全防护技术白皮书

Prometheus deployment

Use Hal Library of STM32 to drive 1.54 inch TFT screen (240*240 st7789v)

Implementation of strstr in C language

架构基本概念和架构本质

Cell review: single cell methods in human microbiome research

Idea properties file display \u solution of not displaying Chinese

Tencent cloud deployment lamp_ Experience of building a station
随机推荐
Kubeedge releases white paper on cloud native edge computing threat model and security protection technology
What parameters should be passed in calling integer or character array functions
Machine learning -- model evaluation, selection and verification
Advanced notes (Part 2)
Labelme(一)
CDGA|工业互联网行业怎么做好数据治理?
冲刺金九银十丨熬夜半个月汇集大厂Android岗1600道面试真题
通信网络基础知识01
【NPP安装插件】
Left alignment function of Lua language (handwriting)
MySQL命令语句(个人总结)
认识中小型局域网WLAN
Why is there no log output in the telnet login interface?
Source code analysis of scripy spider
Leetcode Day1 score ranking
数字滤波器设计——Matlab
Servlet学习笔记
Array method added in ES6
MySQL8 Status Variables: Internal Temporary Tables and Files
In the second half of 2022, the system integration project management engineer certification starts on August 20