C语言抽奖系统
时间: 2023-10-04 12:13:44 浏览: 131
好的,下面是一个简单的C语言抽奖系统的代码示例:
```c
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
int num, guess, count = 0;
srand(time(0)); // 初始化随机数种子
num = rand() % 100 + 1; // 生成一个1~100之间的随机数
printf("欢迎参加抽奖活动!\n");
printf("每位参与者有3次机会猜中幸运数字,数字范围是1~100。\n");
while (count < 3) {
printf("请输入你的猜测:");
scanf("%d", &guess);
count++;
if (guess == num) {
printf("恭喜你,猜对了!你获得了大奖!\n");
break;
}
else if (guess > num) {
printf("猜测的数字太大了,请再试一次。\n");
}
else {
printf("猜测的数字太小了,请再试一次。\n");
}
}
if (count == 3) {
printf("很遗憾,你没有猜对。幸运数字是%d。\n", num);
}
return 0;
}
```
这个抽奖系统会生成一个1~100之间的随机数,然后让用户输入猜测的数字,最多可以猜3次。如果用户猜对了,就会获得大奖;否则,会告诉用户幸运数字是多少。
阅读全文
相关推荐
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![doc](https://img-home.csdnimg.cn/images/20241231044833.png)
![txt](https://img-home.csdnimg.cn/images/20241231045021.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)