Advertisement
LisunovaMaryna

delphi lab 2 1 error

Oct 20th, 2023 (edited)
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 3.05 KB | None | 0 0
  1. program Lab2_1;
  2.  
  3. var
  4.     Arr: Array Of Real;
  5.     I, K, LengthArr, J, N: Integer;
  6.     NearestNum, SetValue, Buffer: Real;
  7.     IsCorrect: Boolean;
  8.  
  9. begin
  10.     Writeln('The program finds the number of the nearest members of the sequence.');//k chisly dopisat'
  11.     Write('Enter length of subsequence: ');
  12.     repeat
  13.         IsCorrect := True;
  14.         try
  15.             Read(LengthArr);
  16.         except
  17.             Write('Symbols have been entered. Enter the number: ');
  18.             IsCorrect := False;
  19.         End;
  20.         if (IsCorrect) and ((LengthArr < 2) Or (LengthArr > 2000000000)) Then
  21.         begin
  22.             IsCorrect := False;
  23.             Write('A negative value or zero was entered or exceeding permissible limits. Enter a valid value: ');
  24.         end;
  25.     until IsCorrect;
  26.     SetLength(Arr, LengthArr);
  27.    
  28.     Write('Enter elements of subsequence: ');
  29.     for I := Low(Arr) To High(Arr) Do
  30.     begin
  31.         repeat
  32.             IsCorrect := True;
  33.             try
  34.                 Read(Arr[I]);
  35.             except
  36.                 Write('Symbols have been entered. Enter the number: ');
  37.                 IsCorrect := False;
  38.             End;
  39.             if (IsCorrect) and (Arr[I] < -2000000000) and (Arr[I] > 2000000000) Then
  40.             begin
  41.                 IsCorrect := False;
  42.                 Write('Exceeding permissible limits. Enter a valid value: ');
  43.             end;
  44.         until IsCorrect;
  45.     end;
  46.    
  47.     for I := 0 to LengthArr - 2 do
  48.         for J := 1 to LengthArr - 1 do
  49.             if Arr[I] > Arr[J] then
  50.             begin
  51.                 Buffer := Arr[I];
  52.                 Arr[I] := Arr[J];
  53.                 Arr[J] := Buffer;
  54.             end;
  55.    
  56.     //вывод масіва
  57.     for I := Low(Arr) To High(Arr) Do
  58.         Write(Arr[I], ' ');
  59.    
  60.     {Write('Enter real value: ');
  61.     repeat
  62.         IsCorrect := True;
  63.         try
  64.             Read(SetValue);
  65.         except
  66.             Write('Symbols have been entered. Enter the number: ');
  67.             IsCorrect := False;
  68.         End;
  69.         if (IsCorrect) and (SetValue < -2000000000) and (SetValue > 2000000000) Then
  70.         begin
  71.             IsCorrect := False;
  72.             Write('Exceeding permissible limits. Enter a valid value: ');
  73.         end;
  74.     until IsCorrect;
  75.    
  76.     if SetValue < Arr[Low(Arr)] Then
  77.         Write('The entered value is less than the smallest term of the sequence.')
  78.     Else
  79.     begin
  80.         NearestNum := Arr[Low(Arr)];
  81.         I := Low(Arr);
  82.         while SetValue > Arr[I] do
  83.         begin
  84.             k := I;
  85.             inc(I);
  86.         end;
  87.         NearestNum := Arr[k];
  88.        
  89.         repeat
  90.             IsCorrect := True;
  91.             if NearestNum < Arr[k + 1] Then
  92.                 write('The nearest element of the sequence numbered ', k)
  93.             else
  94.             begin
  95.                 IsCorrect := False;
  96.                 inc(k);
  97.             end;
  98.         until IsCorrect;
  99.         //y=5, x: 3 4 5 6;
  100.         //y=5, x: 3 4 5 5 6;
  101.         //y=5, x: 3 4 6 7;
  102.         //y=-5, x: 1 2 3 4;
  103.     end;}
  104. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement