fork download
  1. with Ada.Numerics; use Ada.Numerics;
  2. with Ada.Text_IO; use Ada.Text_IO;
  3. with Ada.Integer_Text_IO;
  4.  
  5. procedure Test is
  6. subtype Real is Long_Float digits 15;
  7. package Real_Text_IO is new Ada.Text_IO.Float_IO (Real); use Real_Text_IO;
  8.  
  9. EPS : constant Real := 5.0E-9;
  10. A : Real := 0.0;
  11. N : Natural := 0;
  12. S, R_Pi : Real;
  13. begin
  14. loop
  15. A := (-1.0)**N * (1.0 / (6.0 * Real (N) + 1.0) +
  16. 1.0 / (6.0 * Real (N) + 5.0));
  17. S := S + A;
  18. N := N + 1;
  19. exit when abs (A) <= EPS;
  20. end loop;
  21.  
  22. R_Pi := S * 3.0;
  23. Put ("Eps = "); Put (EPS, 1, 0); New_Line;
  24. Put ("Ист. Pi = "); Put (Pi, 1, 20); New_Line;
  25. Put ("Расч. Pi = "); Put (R_Pi, 1, 20); New_Line;
  26. Put ("N = "); Ada.Integer_Text_IO.Put (N, 0); New_Line;
  27. end Test;
  28.  
Success #stdin #stdout 4.24s 5820KB
stdin
Standard input is empty
stdout
Eps      = 5.0E-09
Ист. Pi  = 3.14159265358979312000E+00
Расч. Pi = 3.14159264609151889000E+00
N        = 66666668