-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestdata.c
106 lines (94 loc) · 1.79 KB
/
testdata.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include<stdio.h>
#include<math.h>
#include<string.h>
#define MAX = 50000
#define SIZE 1000
int main(int argc ,char * argv[])
{ int i,j,k=0;
struct cord
{
float x;
float y ;
};
typedef struct cord cr;
cr E[SIZE] ;
float sqroot(float m)
{
float i=0;
float x1,x2;
while( (i*i) <= m )
i+=0.1;
x1=i;
int j;
for(j=0;j<10;j++)
{
x2=m;
x2/=x1;
x2+=x1;
x2/=2;
x1=x2;
}
return x2;
}
FILE *source,*f1,*f2,*f3;
f1=fopen("data.txt","w");
f2 =fopen("opt.txt","r");
/* f3 =fopen("ch.txt","r"); */
float sum = 0;
float w[SIZE][SIZE];
int n ;
char pgm[25];
printf("Enter the size ");
scanf("%d",&n);
strcpy(pgm,argv[1]);
source = fopen(pgm,"r");
if(source==NULL)
{
fprintf(stderr,"FILE %s not found\n",pgm);
return 1;
}
for(i=0;i<n;i++)
{
fscanf(source," %d ",&j) ;
fscanf(source," %f ",&E[i].x) ;
fscanf(source," %f ",&E[i].y) ;
}
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{ if(i!=j)
w[i][j] = (sqroot((pow(E[i].x - E[j].x,2)) + (pow(E[i].y - E[j].y,2))))/10 ;
else
w[i][j] = 50000 ;
}
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{ if(i!=j)
fprintf(f1," %f ",w[i][j]) ;}
int s,v=0,a ;
float sum1=0;
fscanf(f2," %d ",&s);
printf(" %d ",s);
a = s;
for(i=0;i<n;i++)
{ if(i!=n-1)
{ fscanf(f2," %d ",&v) ;
sum += w[s-1][v-1];
s=v;
}
else
{ sum+= w[s-1][a-1] ;
}
}
/* for(i=0;i<2*n;i=i+2)
{ fscanf(f3," %d ",&s);
fscanf(f3," %d ",&v);
sum1+= w[s-1][v-1];
}
printf(" %f ",sum1) ; */
printf(" %f ",sum);
fclose(source);
fclose(f1);
fclose(f2) ;
/* fclose(f3) ; */
return 0;
}