mfc生成随机数
[此问题的推荐答案]
此段程序可以满足你的要求,可以运行,自己有什么另外的用法,修改一下就行了
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <iostream>
using std::cout;
using std::endl;
using std::ios;
#include <fstream>
using std:fstream;
#include <iomanip>
using std::setw;
int main(int argc, char* argv[])
{
printf("Hello World!\n");
int i=0;
int k=0;
srand((unsigned)time( NULL ));
ofstream ofs("aaa.txt",ios:ut);
for(int j=1;j<=90;j++)
{
k=rand()%200+1;
printf("%10d",k);
ofs<<setw(10)<<k;
if(j%3 == 0)
{
printf("\n");
ofs<<endl;//三个数换行
}
}
ofs.close();
return 0;
}
文件操作就这么几行:
ofstream ofs("aaa.txt",ios:ut);
ofs<<setw(10)<<k;
ofs<<endl;
ofs.close();
随机数操作:
srand((unsigned)time( NULL ));
k=rand()%200+1;
温馨提示:答案为网友推荐,仅供参考