program GetNearX Type TIntArray array 25 of integer TPair record Value

 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
program GetNearX;
Type
TIntArray = array [1..25] of integer;
TPair = record
Value1:integer;
Value2:Integer;
end;
procedure FindNearX(X:integer;yArray:TIntArray;var result: TPair);
var
i,j:integer;
d,curd:double;
begin
curd := abs(x - (yArray[1] + yArray[2]) / 2);
result.Value1 := 1;
result.Value2 := 2;
for I := 2 to 24 do
begin
for j := i+1 to 25 do
begin
d := abs( x - (yArray[i] + yArray[j]) / 2);
if d < curd then
begin
Result.Value1 := i;
Result.Value2 := j;
curd := d;
end;
end;
end;
end;
var
yArray:TIntArray;
i:integer;
x:integer;
Pair:TPair;
begin
for I := 1 to 25 do
yArray[i] := i;
Write('Enter X:');
ReadLn(X);
FindNearX(X,yArray,Pair);
WriteLn('First:', pAir.Value1,' Second: ', pair.Value2);
WriteLn('Press Enter to exit');
ReadLn;
end.