Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Fortran Help ASAP!!!

Status
Not open for further replies.

skockler8

Programmer
Sep 11, 2012
2
0
0
Hello all,

I am working on a Fortran90 code that will give me an approximation of a few mathematical constants. My code will compile and run, however, my outputs are given as 0.000000 for all constants that I am calculating in the loops. Any help would be greatly appreciated. My code is as follows:

PROGRAM HomeWorkOne_ProbOne

IMPLICIT NONE

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

REAL :: e, EC, pi, n_factorial, x_factorial, gamma
INTEGER :: i, n, x


x = n + 3.0/2.0

n_factorial = 1.0


DO WHILE (n < 10)
DO i = 1, n
n_factorial = n_factorial * i
END DO
e = 1/n_factorial
END DO

DO WHILE (n < 10)
EC = (1.0/n) - (LOG(REAL(n)+1.0)-LOG(REAL(n)))
END DO

DO WHILE (x < 10)
DO i = 1, x
x_factorial = x * i
gamma = (2.0 * x_factorial)/(2.0 * n + 3.0)
END DO
DO i = 1, n
n_factorial = n_factorial * i
END DO
pi = (n_factorial)/((2**(n-(1.0/4.0)*Cos(3.14*(2.0*n+1.0))))+(3.0/4.0)*(3.14**((1.0/4.0)*Cos(3.14*(2*n+1))-(1.0/4.0)))*gamma)
END DO

PRINT *, "Approximate values of:"
PRINT *, "e =", e
PRINT *, "gamma =", EC
PRINT *, "Pi =", pi
PRINT *, "Actual values of :"
PRINT *, "e =", 2.71828182
PRINT *, "gamma =", 0.57721566
PRINT *, "Pi =", 3.14159265

END PROGRAM HomeWorkOne_ProbOne


Thanks for any help!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top