编写程序产生1000个取值范围在100-999之间的随机整数,并将这些整数以文本格式写入到c:\data3.txt中。
老师给的作业,我使用的系统不一样,知道题的解法但不知道代码怎么写,求代码谢谢
编写程序产生1000个取值范围在100-999之间的随机整数,并将这些整数以文本格式写入到c:\data3.txt中。
老师给的作业,我使用的系统不一样,知道题的解法但不知道代码怎么写,求代码谢谢
#include <iostream>
#include <fstream>
#include <time.h>
using namespace std;
int main()
{
srand((unsigned int)time(NULL));
ofstream outfile;
outfile.open("c:\\data3.txt");
int n;
for(int i=0;i<1000;i++)
{
n=rand()%900+100;
outfile << n << " ";
}
outfile.close();
return 0;
}