实战演练:利用srand函数设计随机抽奖系统

   2024-10-01 5530
核心提示:#include stdio.h#include stdlib.h#include time.hint main() {// 设置随机种子srand(time(NULL));// 定义奖品数组char *prizes

#include <stdio.h>#include <stdlib.h>#include <time.h>

int main() {// 设置随机种子srand(time(NULL));

// 定义奖品数组char *prizes[] = {"一等奖", "二等奖", "三等奖", "谢谢参与"};// 生成随机数(0-3),代表抽奖结果int random = rand() % 4;// 输出抽奖结果printf("恭喜你抽中了:%s\n", prizes[random]);return 0;

}

 
举报打赏
 
更多>同类物流大全
推荐图文
推荐物流大全
点击排行

网站首页  |  关于我们  |  联系方式网站留言    |  赣ICP备2021007278号