pi2.rb 284 B

123456789101112131415161718
  1. def divide(int)
  2. return 4.0 / (int * (int + 1) * (int + 2))
  3. end
  4. answer = 3
  5. c = 2
  6. i = 1
  7. while c < 100000 do
  8. if (i % 2 == 0) then
  9. puts (answer = answer - divide(c))
  10. c += 2
  11. else
  12. puts (answer = answer + divide(c))
  13. c += 2
  14. end
  15. i += 1
  16. end