다음 프로그램은 무작위 2차원 그룹을 생성하는 데 사용됩니다
#include<iostream>
#include<fstream>
#include<time.h>
#include<iomanip>//
#include<stdlib.h>
#define N 10
using namespace std;
int CreateArray();//
int ReadArray();//
int main()
{
CreateArray();
ReadArray();
return 1;
}
int CreateArray()
{//
ofstream outfile;//
outfile.open("MyArray.txt",ios::out);
int i,k,j;
srand((unsigned)time(NULL));
outfile.setf(ios::right);// ,
for(i=0;i<N;i++)
{
for(j=0;j<N;j++)
{
k=rand()%99 + 6;
outfile.width(4);// ,
outfile<<k<<" ";
}
outfile<<endl<<endl;
}
outfile.close();
cout<<endl;
return 1;
}
int ReadArray()
{// Array[][]
int Array[N][N],i,j;
ifstream infile("MyArray.txt",ios::in);//
cout.setf(ios::right);// ,
for(i=0;i<N;i++)
for(j=0;j<N;j++)
{//
infile>>Array[i][j];
}
for(i=0;i<N;i++)
{//
for(j=0;j<N;j++)
{
cout.width(4);// ,
cout<<Array[i][j]<<" ";
}
cout<<endl<<endl;
}
infile.close();
return 1;
}