当前位置:网站首页>猜數字遊戲
猜數字遊戲
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
边栏推荐
- P1586 solution to tetragonal theorem
- Excel打开超大csv格式数据
- for()循环参数调用顺序
- The waterfall waterfall flow of uview realizes single column and loads more
- PM2 deploy nuxt related commands
- 【UDS统一诊断服务】四、诊断典型服务(1)— 诊断和通信管理功能单元
- 基于QQwebAPI 查询昵称和头像的爬虫
- Solution to the trial of ycu Blue Bridge Cup programming competition in 2021
- Basic knowledge of network in cloud computing
- grub boot. S code analysis
猜你喜欢
随机推荐
Rust 中的 Cell 共享可变指针
【无标题】
静态成员
[leetcode 59] spiral matrix II
clion安装教程
Export of data
四元数乘法
P1586 solution to tetragonal theorem
Easy to use data set and open source network comparison website
Robocode教程3——Robo机器剖析
Rust的闭包类型(Fn, FnMut, FnOne的区别)
用二进制进行权限管理
MySQL groups are sorted by a field, and the first value is taken
Rust 中的 RefCell
Rust 中的指针:Box、Rc、Cell、RefCell
C array
【UDS统一诊断服务】四、诊断典型服务(2)— 数据传输功能单元
对象数组与对象指针
Rust:单元测试(cargo test )的时候显示 println 的输出信息
Rust 的多线程安全引用 Arc