编写C程序以生成的2D随机数组,以表示无向图的邻接矩阵,
当V小于或等于700时,效果很好
一旦超过,它将在运行时崩溃
任何具体原因?可以进行任何修改以使其可能生成更大的矩阵吗?
#include <stdio.h>
#include <stdlib.h>
#define V 700
int main(){
//CREATE FILE
char v[4] = {'7','0','0','\0'};
FILE *fPointer;
fPointer = fopen ("adjMatrix.txt","w");
fprintf(fPointer,v);
fclose(fPointer);
int graph[V][V];
int i;
int j;
for (i=0;i<V;i++)
{
for(j=0;j<V;j++)
{
if(i==j)
{
graph[i][j] = 0;
}
else
{
graph[i][j] = rand()%10;
graph[j][i] = graph[i][j] ;
}
}
}
//append file
fPointer = fopen ("adjMatrix.txt","a");
for (i=0;i<V;i++)
{
fprintf(fPointer,"\n");
for(j=0;j<V;j++)
{
fprintf(fPointer,"%d ",graph[i][j]);
}
}
fclose(fPointer);
return 0;
}