/* Note:Your choice is C IDE */ //引入标准输入、输出库 #include "stdio.h" //引入系统时间库 #include "time.h" //宏定义,随机数生成函数 #define Random(x) (rand() % x) //函数声明 void print_name(char *pt,int max_size); void prize(); void main() { prize(); } void prize(){ char students[42][20] = { "王旭辉","黄长安","王安","杨嘉辉","卓有权","刘先明", "潘奎任","叶采梦","曹继生","周有静","梁铁成","李新伟", "陈路","韦桂金","郭由冲","钟富豪","黎明忠","蓝森明", "韦小娟","陈冠宏","庄瑞","邹耀销","蒋廷帅","王文森", "徐庆生","李诚","岑立宾","黄培杰","李伟博","李伟杰", "梁锦杰","梁淇岚","刘洪好","刘栩祥","沈志军","唐林逸", "徐景祥","朱明辉","彭彦宁","张健","丘永才","詹永栋", }; //刷新每个学生名字频率控制 const int FREQ = 30000000; const int STUDENT_SIZE = 42; const int NAME_MAX_SIZE = 20; int luck = 0; printf("输入你的幸运号: "); //等待用户输入幸运号码,用来生成随机种子 scanf("%d",&luck); printf(" "); int j=0,i=0; char *cpt = &students[0][0]; //每次使用不同的种子 srand(luck+(int)time(NULL)); while(j++<21) { //随机选择学生 cpt = students[Random(STUDENT_SIZE)]; print_name(cpt,NAME_MAX_SIZE); for(i=0;i<FREQ;i++); //刷新控制台 printf(" "); } //打印中奖信息 printf(" "); printf("-----------恭喜你中奖了------------- "); int si = 4; while(si--) print_name(cpt,NAME_MAX_SIZE); } //打印字符串函数 void print_name(char *pt,int max_size){ while(max_size--){ printf("%c",*pt); pt++; } }