代码如下:
#include <stdio.h>
#include <stdlib.h>
#include <time.h> //用到了time函数
int main()
{
int i,number;
FILE *fp;
int x=123;
srand((unsigned) time(NULL)); //用时间做种,每次产生随机数不一样
fp=fopen("input.txt","w");
if(fp==NULL)
{
printf("create file failed\n");
return -1;
}
for (i=0; i<50; i++)
{
number = rand() % 101; //产生0-100的随机数
fscanf(fp,"%d ", number);
}
fclose(fp);
return 0;
}