Advertisement
LisunovaMaryna

lab1.2 delphi

Sep 26th, 2023 (edited)
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 0.81 KB | None | 0 0
  1. Var
  2.     a, b, n: Integer;
  3.     IsCorrect: Boolean;
  4.  
  5. Begin
  6.     a := 1;
  7.     b := 1;
  8.     Writeln('The program will calculate the n-th term of the Fibonacci series.');
  9.     Write('Enter the Fibonacci series member number: ');
  10.     Repeat
  11.         Try
  12.             IsCorrect := True;
  13.             Read(n);
  14.             If (n < 0) Or (n = 0) Then
  15.             Begin
  16.                 IsCorrect := False;
  17.                 Write('A negative value or zero was entered. Enter a valid value: ');
  18.             End;
  19.         Except
  20.             Begin
  21.                 Write('Symbols have been entered. Enter the number: ');
  22.                 IsCorrect := False;
  23.             End;
  24.          End;
  25.     Until IsCorrect;
  26.    
  27.     For Var i := 2 To n - 1 Do
  28.     Begin
  29.         b := a + b;
  30.         a := b - a;
  31.     End;
  32.     Write(b);
  33. End.
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement