Advertisement
Sauka1337

Untitled

Sep 25th, 2023
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.38 KB | None | 0 0
  1. program var_27_task_3;
  2.  
  3. {$APPTYPE CONSOLE}
  4.  
  5. {$R *.res}
  6.  
  7. uses
  8.   System.SysUtils;
  9.  
  10. var
  11.     Pi : Real;
  12.     Precision, K : Integer;
  13.     I : Integer = 0;
  14.     Numerator : Integer = 1;
  15.     FirstDenominator : Integer = 1;
  16.     SecondDenominator : Integer = 3;
  17.     Counter : Integer = 1;
  18.  
  19. begin
  20.     Precision := 0;
  21.     While Precision <= 0 do
  22.     begin
  23.         try
  24.             WriteLn('Enter precision (number of iterations) : ');
  25.             ReadLn(Precision);
  26.         except
  27.         on E: Exception do
  28.             Writeln(E.ClassName, ': ', E.Message);
  29.     end;
  30.  
  31.     if Precision<=0 then
  32.         begin
  33.             WriteLn('Input Error. Check if the data is correct.');
  34.         end;
  35.     end;
  36.  
  37.     While I < (Precision*3) do
  38.     begin
  39.         if Counter < 3 then
  40.             begin
  41.                 Pi := Pi + Numerator/(FirstDenominator*SecondDenominator);
  42.             end
  43.         else if Counter = 3 then
  44.             begin
  45.                 Pi := Pi - Numerator/(FirstDenominator*SecondDenominator);
  46.             end;
  47.  
  48.         FirstDenominator := FirstDenominator + 4;
  49.         SecondDenominator := SecondDenominator + 4;
  50.         Counter := Counter + 1;
  51.         if Counter > 3 then
  52.             begin
  53.                 Counter := 1;
  54.             end;
  55.         I := I + 1;
  56.     end;
  57.  
  58.  
  59.     WriteLn('Pi value = ', Pi*8);
  60.     Writeln('Press <enter> to quit...');
  61.     Readln;
  62. end.
  63.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement