На плоскости заданы своими координатами n точки. составить программу , определяющую между какими из пар точек самое большое рассотяние . Указание координаты точек занести в массив. Одну из частей подпрограммы оформить процедурой или функцией.паскаль
var points: array[1..n] of Point; maxDistance: real; point1, point2: Point;
function Distance(p1, p2: Point): real; begin Distance := sqrt(sqr(p2.x - p1.x) + sqr(p2.y - p1.y)); end;
procedure FindMaxDistance; var i, j: integer; d: real; begin maxDistance := 0; for i := 1 to n do begin for j := i + 1 to n do begin d := Distance(points[i], points[j]); if d > maxDistance then begin maxDistance := d; point1 := points[i]; point2 := points[j]; end; end; end; end;
begin for i := 1 to n do begin write('Enter x coordinate of point ', i, ': '); readln(points[i].x); write('Enter y coordinate of point ', i, ': '); readln(points[i].y); end;
FindMaxDistance;
writeln('The maximum distance is between points (', point1.x, ', ', point1.y, ') and (', point2.x, ', ', point2.y, ')'); writeln('Distance: ', maxDistance:0:2); end.
program MaxDistance;
const
n = 5;
type
Point = record
x, y: integer;
end;
var
points: array[1..n] of Point;
maxDistance: real;
point1, point2: Point;
function Distance(p1, p2: Point): real;
begin
Distance := sqrt(sqr(p2.x - p1.x) + sqr(p2.y - p1.y));
end;
procedure FindMaxDistance;
var
i, j: integer;
d: real;
begin
maxDistance := 0;
for i := 1 to n do
begin
for j := i + 1 to n do
begin
d := Distance(points[i], points[j]);
if d > maxDistance then
begin
maxDistance := d;
point1 := points[i];
point2 := points[j];
end;
end;
end;
end;
begin
for i := 1 to n do
begin
write('Enter x coordinate of point ', i, ': ');
readln(points[i].x);
write('Enter y coordinate of point ', i, ': ');
readln(points[i].y);
end;
FindMaxDistance;
writeln('The maximum distance is between points (', point1.x, ', ', point1.y, ') and (', point2.x, ', ', point2.y, ')');
writeln('Distance: ', maxDistance:0:2);
end.