-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfindFarestPair.cpp
More file actions
40 lines (40 loc) · 871 Bytes
/
Copy pathfindFarestPair.cpp
File metadata and controls
40 lines (40 loc) · 871 Bytes
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
#include <stdio.h>
#include <math.h>
float x[100], y[100];
float do_dai(int i, int j)
{
return sqrt(pow(x[i] - x[j], 2) + pow(y[i] - y[j], 2));
}
void nhapsl(int n)
{
int i;
for (int i = 0; i<=n; ++i)
{
printf("\nNhap toa do x, y cua diem thu %d ", i);
scanf("%f%f", &x[i], &y[i]);
}
}
int main()
{
int n, i, j, imax, jmax;
float d, dmax;
printf("\nSo diem N = ");
scanf("%d", &n);
nhapsl(n);
dmax = do_dai(1, 2); imax = 1; jmax = 2;
for (i=1; i<=n-1; ++i)
{
for (j=i+1; j<=n; ++j)
{
d = do_dai(i, j);
if (d > dmax)
{
dmax = d;
imax = i;
jmax = j;
}
}
}
printf("\nDoan thang lon nhat co do dai = %0.2f", dmax);
printf("\nDi qua 2 diem co chi so la %d, %d", imax, jmax);
}