c语言随机抽人代码_C语言:倒计时,双色球,抽奖代码演示

C语言是一门面向过程的计算机编程语言,与C++、Java等面向对象编程语言有所不同。C语言的设计目标是提供一种能以简易的方式编译、处理低级存储器、仅产生少量的机器码以及不需要任何运行环境支持便能运行的编程语言。C语言描述问题比汇编语言迅速,工作量小、可读性好,易于调试、修改和移植,而代码质量与汇编语言相当。C语言一般只比汇编语言代码生成的目标程序效率低10%~20%。因此,C语言可以编写系统软件。

207fd325b9d16acdd76816c4d4cebd84.png

c0641e0616eda1ac9154818ed2378a1e.gif

69c7331497e9feb7a9f737d9bbfd12a6.gif

2020年6月15号晚上,ICT虚拟公司孵化中心软件开发部部长黄国强组织成员在中兴通讯电信学院工程实训室开展了一次C语言培训。

1812e02cf4137fd97b5740991b24403d.png

21c761475ef8887251648561c41be894.png

e929c2e074ed8e7db2d3e5a4fb282ba4.png

0792d82f5c9d694a7a140d8ff1134f01.png

9e2d117da9b062b4b8d0755b9ce557e3.gif

aef07df22d34ce90887cec3a37eeac58.gif

15f4b507e8eb24fa12ee3dee93690726.png

4ba0ad7eca0107f82d13ce2e0677d81d.gif

03e1916170c3ce49ba536e69c689579c.gif

通过研究与讨论,完整的写出了双色球、随机抽奖、倒计时三个程序,代码如下:

双色球的编写代码如下:

3d77b5fc121aa2cd59d249702bcc4fb0.png

#include #include #include   int main() { srand((unsigned int)time(NULL)); int i = 0; int j = 0; int temp; int red[6]; int blue; for (i = 0; i < 6;) { temp = rand() % 33 + 1; for (j = 0; j < i; j++) { if (red[j] == temp) { break; } } if (j == i) { red[i] = temp; i++; } } blue = rand() % 16 + 1; printf("Red : "); for (i = 0; i < 6; i++) { printf("%d ", red[i]); } printf("\n"); printf("Blue : %d\n", blue); return 0; }

ba02e9f3832182f96eef125d87bd2991.gif

随机抽奖编写代码如下:

0c4b87e378ae690d6258511d697996f3.png

4dc871a67fd7185b97ffbf57a392d7ea.png

#include #include #include #include #include #include struct data { char id[20]; char name[20]; }; int t1, t2, t3; struct data information[110];              struct data prize1[110];                   struct data prize2[110];                  struct data prize3[110];                   int people = 0;                            int people1 = 1, people2 = 2, people3 = 3;      char strid[20]; void Read_information(); void Print_menu(); void Begin_luck(); void Delet_information(); void main() { Read_information(); Print_menu(); } void Read_information() { FILE* fp = fopen("D:\\ad.txt", "r"); while (!feof(fp)) { fscanf(fp, "%s%s", information[people].id, information[people].name); people++; } fclose(fp); } void Print_menu() { int choose; while (1) { system("cls"); printf("\n\n"); printf("\t\t\t*********************************************************\n"); printf("\t\t\t*\t \t\t\t*\n"); printf("\t\t\t*\t \t\t*\n", people); printf("\t\t\t*\t\t\t\t\t\t\t*\n"); printf("\t\t\t*\t\t开始抽奖请按1\t\t\t\t*\n"); printf("\t\t\t*\t\t结束程序请按0\t\t\t\t*\n"); printf("\t\t\t*\t\t\t\t\t\t\t*\n"); printf("\t\t\t*********************************************************\n"); printf("\n\n\t\t\t\t\t请输入选项:"); scanf("%d", &choose); switch (choose) { case 0: return; case 1: Begin_luck(); break; } } } void Begin_luck()  { if (people1 == 0 || people2 == 0 || people3 == 0) { printf("按任意键返回\n"); getch(); return; } if ((people1 + people2 + people3) > people) { printf("中奖人数超过总人数,请重新设置!!!!\n"); printf("按任意键返回\n"); getch(); return; } int i, j = 0, choose, t; system("cls"); printf("下面开始抽取三等奖人员,按任意键继续\n"); getch(); while (people3--) { if (people3 < 0) break; srand((unsigned)time(0)); t = rand() % people; prize3[j++] = information[t]; strcpy(strid, information[t].id); Delet_information(); } printf("以下是三等奖名单,按任意键继续\n"); for (i = 0; i < j; i++) printf("%s\n", prize3[i].name); getch(); printf("下面开始抽取二等奖人员,按任意键继续\n"); getch(); while (people2--) { if (people2 < 0) break; srand((unsigned)time(0)); t = rand() % people; prize2[j++] = information[t]; strcpy(strid, information[t].id); Delet_information(); } printf("以下是二等奖名单,按任意键继续\n"); for (; i < j; i++) printf("%s\n", prize2[i].name); getch(); printf("下面开始抽取一等奖人员,按任意键继续\n"); getch(); while (people1--) { if (people1 < 0) break; srand((unsigned)time(0)); t = rand() % people; prize1[j++] = information[t]; strcpy(strid, information[t].id); Delet_information(); } printf("以下是一等奖名单,按任意键继续\n"); for (; i < j; i++) printf("%s\n", prize1[i].name); getch(); people = 0; Read_information(); people1 = t1, people2 = t2, people3 = t3; } void Delet_information()   { int i, j; for (i = 0; i < people; i++) if (strcmp(information[i].id, strid) == 0) { people--; for (j = i; j < people; j++) information[j] = information[j + 1]; return; } }

11de1a8eec88bd79c30fda6b51a30d77.gif

倒计时编写代码如下:

43eb50c03d4f4da80c22de34c824ecd7.png

#include  #include  int main(void) { int minutes; printf("请输入分钟数:\n"); scanf_s("%d", &minutes); printf("\r还剩 %d 分钟 00 秒 结束", minutes); Sleep(1000); for (--minutes; minutes >= 0; --minutes) { for (int i = 59; i >= 0; --i) { printf("\r还剩 %d 分钟 %d 秒 结束", minutes, i);Sleep(1000); }; }; printf("计时结束\n"); system("PAUSE"); return 0; }

6c9e44a381ea4f11a2969061e771bdc5.png

c语言是一门非常有趣的学科,欢迎感兴趣的同学在下方评论区留言

79db7ceb3051ae55cc223bfc5ada708f.png

END

8f994d353298a5115a320da714ca76c6.png

扫码关注我们

出品:中兴通讯电信学院
指导老师:刘建明
文案编辑:李婉婷
排版:鲁兴东

f84188b784155411ca34fab6413e895c.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值