Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program Pi
- implicit none
- ! -----------------------------------------------Declare
- real*8 lengtha,lengthb,lengthc,pi,redpoints
- integer*4 nrtries,i
- ! -----------------------------------------------Input
- print*, "Enter the number of points:"
- read*, nrtries
- redpoints = 0
- ! -----------------------------------------------Compute
- do i=1,nrtries
- lengtha = rand(0)
- lengthb = rand(0)
- lengthc = dsqrt(lengtha**2 + lengthb**2)
- if (lengthc < 1) then
- redpoints + 1;
- endif
- nrtries +1
- i + 1
- end do
- pi = 4*(redpoints / nrtries)
- ! -----------------------------------------------Output
- print*, "The approximate value of PI is: "
- print*, pi
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement