https://www.myziyuan.com/
- 远古
- http://www.pudn.com/downloads100/sourcecode/others/detail407380.html
- 2021-02-23 00:20:01
- 亚亚
- #include <stdio.h>#include <stdlib.h>#include <time.h>void main(){ //生成随机数种子 srand(time(NULL)); int n = 100; //假设有100人 int m = 1 + rand()%100; //取m为1~100之间的随机数 getchar(); //等待输入 printf("中奖的是第%d人", m);}
- 2021-02-11 22:16:34
- ydcker
- C语言根据随机数编写一个抽奖程序,#include#include #include #include #include #include #define AWARDER_NUM 10typedef struct tag_award { char ID[20]; char name[20]; char telNo[20]; char address[50];}AWARDER;AWARDER * awarder = new AWARDER[AWARDER_NUM];int first_award[1] = {-1};int second_award[2] = {-1,-1};int third_award[5] ={-1,-1,-1,-1,-1};int awarder_num = 0;void info_login(){ if(awarder_num >= AWARDER_NUM) { AWARDER * new_awarder = new AWARDER[awarder_num + AWARDER_NUM]; memcpy(new_awarder,awarder,awarder_num*sizeof(AWARDER)); delete awarder; awarder = new_awarder; } printf("身份证号:"); scanf("%s",awarder[awarder_num].ID); printf("姓名:"); scanf("%s",awarder[awarder_num].name); printf("电话号码:"); scanf("%s",awarder[awarder_num].telNo); printf("家庭住址:"); scanf("%s",awarder[awarder_num].address); awarder_num++;}void info_delete(){ char name[20]; printf("输入您要删除的抽奖者的姓名:"); scanf("%s",name); for(int i=0;i= awarder_num -1) memcpy(new_award,awarder,sizeof(AWARDER) * (awarder_num - 1)); else { memcpy(new_award,awarder,sizeof(AWARDER) * i); memcpy(new_award+i,awarder+i+1,sizeof(AWARDER) * (awarder_num - i - 1)); } awarder_num--; delete awarder; awarder = new_award; } }}void info_modify(){ char name[20]; printf("输入您要修改的抽奖者的姓名:"); scanf("%s",name); for(int i=0;i"); int operate; fflush(stdin); scanf("%d",&operate); switch(operate) { case 1: info_login(); break; case 2: info_delete(); break; case 3: info_modify(); break; case 4: award(); break; case 5: info_show(); break; case 6: return false; default: break; } printf("\n操作完成。\n"); return true;}void main(){ while(raise());}
- 2021-02-11 22:16:34