loading
main.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define plithos_simeiwn 20
#define Xmin 719604.0 
#define Xmax 722538.0 
#define Ymin 4328469.0 
#define Ymax 4332907.0 
#define Radius 500
#define Total_Regions 2

struct Point_of_Interest
{
    char id[10];
    double x;
    double y;
};
  
struct Point_of_Interest Points[plithos_simeiwn];

double Distances [plithos_simeiwn][plithos_simeiwn];

double Average_Distances [plithos_simeiwn];

void Data_Points()
{
    int i;
	for (i=0;i<plithos_simeiwn;i++)
    {
    	printf("Dose ton kodiko tou %dou shmeiou:\n",i+1);
    	scanf("%s",Points[i].id);
    	do
    	{
    		printf("Dose th x shnistosa tou %d ou shmeiou:(719604-722538)\n",i+1);
    		scanf("%lf",&Points[i].x);
		}while(Points[i].x<Xmin||Points[i].x>Xmax);
		do
    	{
    		printf("Dose thn y shnistosa tou %d ou shmeiou:(4328469-4332907)\n",i+1);
    		scanf("%lf",&Points[i].y);
		}while(Points[i].y<Ymin||Points[i].y>Ymax);
	}
}

double Euclidean_Distance (int i, int j)
{
	return sqrt(pow(Points[i].x-Points[j].x,2)+pow(Points[i].y-Points[j].y,2));
}

void Populate_Distance_Matrix()
{
	int i,j;
	for(i=0;i<plithos_simeiwn;i++)
		for(j=0;j<plithos_simeiwn;j++)
			Distances[i][j]=Euclidean_Distance(i,j);
}

void Average_Distance_Matrix()
{
	int i,j;
	double sum;
	for(i=0;i<plithos_simeiwn;i++)
	{
		sum=0;
		for(j=0;j<plithos_simeiwn;j++)
			sum=sum+Distances[i][j];
		Average_Distances[i]=sum/(plithos_simeiwn-1);
	}
}

int main()
{
	int i,j,k1,k2,Regions[Total_Regions];
	double average,sum=0,max,average1[plithos_simeiwn],average2[plithos_simeiwn];
	
    Data_Points(); 
    printf("\n \n Data Entered \n \n");
    for (i=0; i<plithos_simeiwn;i++)
	printf("id=%s  x=%lf y=%lf \n", Points[i].id, Points[i].x, Points[i].y);
    printf("\n \n Distance Matrix \n \n");

    Populate_Distance_Matrix(); 

    for (i=0; i<plithos_simeiwn; i++)
    {
        printf("\n");
        for (j=0; j<plithos_simeiwn; j++)
            printf("%6.2lf\t", Distances[i][j]);
    }
    printf("\n \n Average Distance Matrix \n \n");

    Average_Distance_Matrix(); 

    for (i=0; i<plithos_simeiwn;i++)
		printf("id=%s  Average=%lf \n", Points[i].id, Average_Distances[i]);
	for(i=0;i<plithos_simeiwn;i++)
		sum=sum+Average_Distances[i];
	average=sum/plithos_simeiwn;
	k1=0;
	k2=0;
	for(i=0;i<plithos_simeiwn;i++)
		if(Average_Distances[i]<average)
		{
			Regions[i]=100;
			average1[k1]=Average_Distances[i];
			k1++;
		}
		else
		{
			Regions[i]=200;
			average2[k2]=Average_Distances[i];
			k2++;
		}
	max=average1[0];
	for(i=1;i<k1;i++)
		if(average1[i]>max)
			max=average1[i];
	printf("Plithos keraion pou prepei na egkatastathoun sthn perioxh 1:%lf\n",max/500);
	max=average2[0];
	for(i=1;i<k2;i++)
		if(average2[i]>max)
			max=average2[i];
	printf("Plithos keraion pou prepei na egkatastathoun sthn perioxh 2:%lf\n",max/500);
 	system("pause");
    return 0;
}