Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program Lab2_1;
- var
- Arr: Array Of Real;
- I, K, LengthArr, J, N: Integer;
- NearestNum, SetValue, Buffer: Real;
- IsCorrect: Boolean;
- begin
- Writeln('The program finds the number of the nearest members of the sequence.');//k chisly dopisat'
- Write('Enter length of subsequence: ');
- repeat
- IsCorrect := True;
- try
- Read(LengthArr);
- except
- Write('Symbols have been entered. Enter the number: ');
- IsCorrect := False;
- End;
- if (IsCorrect) and ((LengthArr < 2) Or (LengthArr > 2000000000)) Then
- begin
- IsCorrect := False;
- Write('A negative value or zero was entered or exceeding permissible limits. Enter a valid value: ');
- end;
- until IsCorrect;
- SetLength(Arr, LengthArr);
- Write('Enter elements of subsequence: ');
- for I := Low(Arr) To High(Arr) Do
- begin
- repeat
- IsCorrect := True;
- try
- Read(Arr[I]);
- except
- Write('Symbols have been entered. Enter the number: ');
- IsCorrect := False;
- End;
- if (IsCorrect) and (Arr[I] < -2000000000) and (Arr[I] > 2000000000) Then
- begin
- IsCorrect := False;
- Write('Exceeding permissible limits. Enter a valid value: ');
- end;
- until IsCorrect;
- end;
- for I := 0 to LengthArr - 2 do
- for J := 1 to LengthArr - 1 do
- if Arr[I] > Arr[J] then
- begin
- Buffer := Arr[I];
- Arr[I] := Arr[J];
- Arr[J] := Buffer;
- end;
- //вывод масіва
- for I := Low(Arr) To High(Arr) Do
- Write(Arr[I], ' ');
- {Write('Enter real value: ');
- repeat
- IsCorrect := True;
- try
- Read(SetValue);
- except
- Write('Symbols have been entered. Enter the number: ');
- IsCorrect := False;
- End;
- if (IsCorrect) and (SetValue < -2000000000) and (SetValue > 2000000000) Then
- begin
- IsCorrect := False;
- Write('Exceeding permissible limits. Enter a valid value: ');
- end;
- until IsCorrect;
- if SetValue < Arr[Low(Arr)] Then
- Write('The entered value is less than the smallest term of the sequence.')
- Else
- begin
- NearestNum := Arr[Low(Arr)];
- I := Low(Arr);
- while SetValue > Arr[I] do
- begin
- k := I;
- inc(I);
- end;
- NearestNum := Arr[k];
- repeat
- IsCorrect := True;
- if NearestNum < Arr[k + 1] Then
- write('The nearest element of the sequence numbered ', k)
- else
- begin
- IsCorrect := False;
- inc(k);
- end;
- until IsCorrect;
- //y=5, x: 3 4 5 6;
- //y=5, x: 3 4 5 5 6;
- //y=5, x: 3 4 6 7;
- //y=-5, x: 1 2 3 4;
- end;}
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement