Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. program Pi
  2. implicit none
  3. ! -----------------------------------------------Declare
  4. real*8 lengtha,lengthb,lengthc,pi,redpoints
  5. integer*4 nrtries,i
  6. ! -----------------------------------------------Input
  7. print*, "Enter the number of points:"
  8. read*, nrtries
  9. redpoints = 0
  10. ! -----------------------------------------------Compute
  11. do i=1,nrtries
  12. lengtha = rand(0)
  13. lengthb = rand(0)
  14. lengthc = dsqrt(lengtha**2 + lengthb**2)
  15. if (lengthc < 1) then
  16.     redpoints + 1;
  17. endif
  18. nrtries +1
  19. i + 1
  20. end do
  21. pi = 4*(redpoints / nrtries)
  22. ! -----------------------------------------------Output
  23. print*, "The approximate value of PI is: "
  24. print*, pi
  25. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement