#include <stdio.h> #include <stdlib.h> //<stdlib.h>用于调用 rand(), #include <time.h> //声明time 时间不可逆转一直在变 #include <Windows.h> //<Windows.h> 用于清屏 #include <conio.h> //<conio.h> 用按键用的 #define MAX_NUM 9999 int main() { FILE *fp = fopen("data.txt", "rb"); char numa[20]; while(!feof(fp)) { fscanf(fp,"%d",&numa); printf("%d ",numa); } fclose(fp); int num; srand((unsigned)time(0)); //rand是伪随机,所以先弄srand,才能是真的随机数 while (1) { if (!_kbhit()) { num = rand()%(999-100+1)+100; //rand()用法:rand()%(上限-下限+1)+下限 printf("抽奖中....%d\n",num); Sleep(10); //以毫秒计时 system("cls"); } //system("cls")作用:清屏 else break; } printf("抽奖结果是:%d\n",num); return 0; }