貌似随机数的讨论目前没有更新的东西了,因为没有需求,所以没有进步。会的那点就够用了,期待下次我能用到随机数,而且是在一个更高的位置上。 将产生随机的数组,随机的内容 #include<iostream> #define Random() srand(time(NULL)) #define Elemtype int using namespace std; FILE *fp; void print(int **a,int m,int n) { for(int i=0;i<m;i++) { for(int j=0;j<n;j++) { cout<<a[i][j]<<" "; if((j+1)%10==0) cout<<endl; } cout<<endl; } } void createMatrix(int **a,int m,int n,FILE *fp) { Random(); for(int i=0;i<m;i++) { for(int j=0;j<n;j++) { a[i][j]=rand()%10000; fprintf(fp,"%d ",a[i][j]); if((j+1)%10==0) fputs("/r/n",fp); } fputs("/r/n",fp); fputs("/r/n",fp); } print(a,m,n); cout<<"/n/n/n"<<endl; } int main() { int k=3; Elemtype **a; for(int i=0;i<k;i++) { Random(); int m=rand()%100; int n=rand()%100; a=new Elemtype*[m]; for(int j=0;j<m;j++) a[j]=new int[n]; if ((fp=fopen("random.txt", "w+")) == 0) { printf("无法创建文件!/n"); exit(1); } createMatrix(a,m,n,fp); } getchar(); }