Saturday, November 6, 2010

Calculate PI with a simple fortran program

In this link (Fer problemes), you can find a montecarlo problem that allows us to find the number PI.

Here, you have one code that could be implemented to simulate this program. It is done in fortran.

PROGRAM calculpi

integer b,d,R
real acirc, aquad
double precision div
b=12345
d=76545
R=1
acirc=0
aquad=0
do i=1,1000000
a=rand(b)
c=rand(d)
b=a
d=c
if ((a**2+c**2)
acirc=acirc+1
endif
if ((a
aquad=aquad+1
endif
div=(acirc/aquad)*4

if (mod(i,10)==0)then
write (*,*) acirc, aquad, div
endif
enddo
STOP
END

No comments:

Post a Comment