fork download
  1. program calculate_pi
  2. implicit none
  3. real :: a, a_new, b, pi, pi_check, t, p
  4. pi = acos(-1.0)
  5. a = 1.0
  6. b = 1.0 / sqrt(2.0)
  7. t = 1.0 / 4.0
  8. p = 1.0
  9. pi_check = (a+b)**2 / (4*t)
  10. do while (abs(pi - pi_check).gt.1e-22)
  11. a_new = (a+b) / 2
  12. b = sqrt(a*b)
  13. t = t - p * (a-a_new)**2
  14. p = 2*p
  15. pi_check = (a+b)**2 / (4*t)
  16. a = a_new
  17. end do
  18. print "(f0.22, 1x, f0.22, 1x, f0.22)", pi, pi_check, pi-pi_check
  19. end program calculate_pi
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
3.1415927410125732421875 3.1415927410125732421875 .0000000000000000000000