Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program var_27_task_3;
- {$APPTYPE CONSOLE}
- {$R *.res}
- uses
- System.SysUtils;
- var
- Pi : Real;
- Precision, K : Integer;
- I : Integer = 0;
- Numerator : Integer = 1;
- FirstDenominator : Integer = 1;
- SecondDenominator : Integer = 3;
- Counter : Integer = 1;
- begin
- Precision := 0;
- While Precision <= 0 do
- begin
- try
- WriteLn('Enter precision (number of iterations) : ');
- ReadLn(Precision);
- except
- on E: Exception do
- Writeln(E.ClassName, ': ', E.Message);
- end;
- if Precision<=0 then
- begin
- WriteLn('Input Error. Check if the data is correct.');
- end;
- end;
- While I < (Precision*3) do
- begin
- if Counter < 3 then
- begin
- Pi := Pi + Numerator/(FirstDenominator*SecondDenominator);
- end
- else if Counter = 3 then
- begin
- Pi := Pi - Numerator/(FirstDenominator*SecondDenominator);
- end;
- FirstDenominator := FirstDenominator + 4;
- SecondDenominator := SecondDenominator + 4;
- Counter := Counter + 1;
- if Counter > 3 then
- begin
- Counter := 1;
- end;
- I := I + 1;
- end;
- WriteLn('Pi value = ', Pi*8);
- Writeln('Press <enter> to quit...');
- Readln;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement