//生成N个小于N的随机数,存入数组a,转存到文件data.txt
void RandToFile(int *a){ srand( (unsigned)time( NULL ) ); //初始化随机数 for(int i=0;i<N;i++) { a[i]=(int)rand()%N; } FILE *fp; if((fp=fopen("data.txt","w"))==NULL){ printf(" error on open data.txt!"); getch(); exit(1); } for(i=0;i<N;i++) fprintf(fp,"%1d ",a[i]); fclose(fp); }