Fortran Programming Question:
Download Questions PDF

Why does not Fortran have intrinsic functions for something as simple as factorial?


Two reasons. Factorial isn't all that common in heavy duty scientific and engineering applications. When it does occur, it almost always in a context where it is more computationally efficient to generate it as you go. You need 2! first then 3!, then 4!, etc. You are basically stuck doing a factorial within the context of a do loop unless you get really good and learn to write "recursive functions", but then you are just fooling yourself and writing another form of do loop. When you are taking the factorial of a large number and don't need an exact answer you can resort to Stirling's Approximation. A Fortran statement that will load the value of this approximation into the variable nfact is.

1 - Try the intrinsic gamma function, which for positive integers has the property
gamma(n+1) = n!
This function is defined for positive real numbers (actually all complex numbers except the negative integers) and hence takes real (NOT INTEGER - haven\\'t tried complex) input - i like to use
GAMMA(n+1D0) = n!
or GAMMA(n+0D0) = (n-1)!
The output is the same precision as input.

2 - to the \\'answer\\' above. It is clear you have nfi. Please don\\'t answer questions you don\\'t actually have a clue about. It took me 5 minutes to find the gamma function after reading your answer - something i needed for my \\'heavy duty\\' computational fluid dynamics program.

Download Fortran Interview Questions And Answers PDF

Previous QuestionNext Question
How do we know where various steps go in a Fortran program?What can we do if our lines wrap around to the next line?