当前位置:网站首页>猜數字遊戲
猜數字遊戲
2022-04-23 06:36:00 【*陌上花開】
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int rander()//產生隨機數
{
time_t ts;
unsigned int n = time(&ts);//獲取時間
srand(n);//初始化隨機種子
int num = rand() % 100 + 1;//隨機數範圍1—100
return num;
}
int main()
{
int a = -1;
char opt = 'a';//選擇
printf("請選擇是否開始遊戲:Y(y)/N(n)\n");
scanf_s("%c", &opt,1);
while (opt == 'Y' || opt == 'y')
{
int num = rander();
int tmp = 0;//標記是否結束循環
while (tmp != 1)
{
printf("請輸入您猜想的數字:", &a);
scanf_s("%d", &a, 1);
if (a == num)
{
printf("猜對啦\n");
tmp = 1;
break;
}
else if (a < num)
{
printf("猜小啦\n");
}
else if (a > num)
{
printf("猜大啦\n");
}
}
printf("請選擇是否繼續遊戲:Y(y)/N(n)\n");
getchar();//接收多輸入的回車
scanf_s("%c", &opt,1);
}
return 0;
}
版权声明
本文为[*陌上花開]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230547207289.html
边栏推荐
猜你喜欢
gcc ,g++,gdb的安装
【UDS统一诊断服务】四、诊断典型服务(6)— 输入输出控制单元(0x2F)
大学概率论与数理统计知识点详细整理
【UDS统一诊断服务】四、诊断典型服务(1)— 诊断和通信管理功能单元
Class inheritance and derivation
Solution to the trial of ycu Blue Bridge Cup programming competition in 2021
Cross domain issues - allow origin header contains multiple values but only one is allowed
【UDS统一诊断服务】二、网络层协议(1)— 网络层概述与功能
【UDS统一诊断服务】四、诊断典型服务(5)— 功能/元件测试功能单元(例行程序功能单元0x31)
Vscode custom comments
随机推荐
Basemap库绘制地图
How SYSTEMd uses / etc / init D script
Animation - Introduction to keyframes
Type conversion in C #
如何安装jsonpath包
从源代码到可执行文件的过程
[untitled]
Rust 中的指针:Box、Rc、Cell、RefCell
Robocode教程8——AdvancedRobot
C#【文件操作篇】PDF文件和图片互相转换
爬取彩票数据
Graduation project, viewing screenshots of epidemic psychological counseling system
Introduction to virtualization features
Robocode教程3——Robo机器剖析
搭建openstack平台
解决ArcGIS分区统计显示太多唯一值执行失败
Completely clean up MySQL win
Detailed arrangement of knowledge points of University probability theory and mathematical statistics
【UDS统一诊断服务】二、网络层协议(2)— 数据传输规则(单帧与多帧)
带默认模板实参的类模板与模板模板形参的匹配