source: proiecte/pgraph/Code/Prim/agenerate1.c @ 129

Last change on this file since 129 was 129, checked in by (none), 14 years ago
File size: 683 bytes
Line 
1// Author Antonio-Gabriel Sturzu
2
3#include<stdio.h>
4#include<stdlib.h>
5#include<time.h>
6
7int main()
8{
9        int n,i,**mat,j;
10        FILE *f=fopen("apm2.in","w");
11
12        printf("Dati n ");
13        scanf("%i",&n);
14
15        mat=(int **) calloc(n*n,sizeof(int *));
16        for(i=0;i<n;i++)
17                mat[i]=(int *) calloc(n,sizeof(int));
18        srand(time(NULL));
19
20        for(i=0;i<n;i++)
21        {
22                for(j=i;j<n;j++)
23                {
24                        if(i==j)
25                                mat[i][j]=0;
26                        else
27                        {
28                                mat[i][j]=mat[j][i]=(rand()%999)+1;
29                        }
30                }
31        }
32        fprintf(f,"%i\n",n);
33        for(i=0;i<n;i++)
34        {
35                for(j=0;j<n;j++)
36                        fprintf(f,"%i ",mat[i][j]);
37                fprintf(f,"%s","\n");
38        }
39        fclose(f);
40        for(i=0;i<n;i++)
41                free(mat[i]);
42        free(mat);
43        return 0;
44}
Note: See TracBrowser for help on using the repository browser.