Calculating Factorials using Stirling Approximation | Python3 program for calculating factorial of a number using Stirling Approximation ; Function for calculating factorial ; value of natural e ; evaluating factorial using stirling approximation ; Driver Code
import math NEW_LINE def stirlingFactorial ( n ) : NEW_LINE INDENT if ( n == 1 ) : NEW_LINE INDENT return 1 NEW_LINE DEDENT e = 2.71 NEW_LINE z = ( math . sqrt ( 2 * 3.14 * n ) * math . pow ( ( n / e ) , n ) ) NEW_LINE return math . floor ( z ) NEW_LINE DEDENT print ( stirlingFactorial ( 1 ) ) NEW_LINE print ( stirlingFactorial ( 2 ) ) NEW_LINE print ( stirlingFactorial ( 3 ) ) NEW_LINE print ( stirlingFactorial ( 4 ) ) NEW_LINE print ( stirlingFactorial ( 5 ) ) NEW_LINE print ( stirlingFactorial ( 6 ) ) NEW_LINE print ( stirlingFactorial ( 7 ) ) NEW_LINE