- #1

skockler8

- 3

- 0

!

PROGRAM HomeWorkOne_ProbOne

IMPLICIT NONE

! Computes an estimation of the exponential function, pi, and the Euler Constant

! Declare all variables

INTEGER(8) :: n

INTEGER, PARAMETER :: max = 100

REAL(8), DIMENSION (max + 2) :: f, DF, p, pi, gamma, e

! Set initial values of variables to approximate

pi = 0.0

gamma = 0.0

e = 0.0

! Calculation of n factorial set equal to f(n)

DO n=1, max

f(1) = 1.0

f(n+1) = f(n)*n

END DO

! Calculation of (2n+1)! set equal to DF(n)

DO n=1, (2*max+1)

DF(1) = 1.0

DF(2) = 1.0

DF(n+2) = DF(n+1)*(2*n+1)

END DO

! Calculation of F/DF set equal to p(n)

DO n=0, max

p(n+1) = f(n+1)/DF(n+1)

END DO

! Loop that will calculate approximation values

DO n=1, max

e(n+2) = (1.0/f(n+1)) + e(n+1)

gamma(n+2) = gamma(n+1) + ((1.0/n)-LOG((n+1.0)/n))

pi(n+2) = p(n+1) + pi(n+1)

END DO

PRINT *, "Approximate values of:"

PRINT *, "e =", e(32)

PRINT *, "gamma =", gamma(32)

PRINT *, "Pi =", pi(32)

PRINT *, "Actual values of :"

PRINT *, "e =", 2.71828182

PRINT *, "gamma =", 0.57721566

PRINT *, "Pi =", 3.14159265

END PROGRAM HomeWorkOne_ProbOne