Calculating Factorials using Stirling Approximation | Java program for calculating factorial of a number using Stirling Approximation ; function for calculating factorial ; evaluating factorial using stirling approximation ; Driver Code
class GFG { public static int stirlingFactorial ( double n ) { if ( n == 1 ) return 1 ; double z ; z = Math . sqrt ( 2 * 3.14 * n ) * Math . pow ( ( n / e ) , n ) ; return ( int ) ( z ) ; } public static void main ( String [ ] args ) { System . out . println ( stirlingFactorial ( 1 ) ) ; System . out . println ( stirlingFactorial ( 2 ) ) ; System . out . println ( stirlingFactorial ( 3 ) ) ; System . out . println ( stirlingFactorial ( 4 ) ) ; System . out . println ( stirlingFactorial ( 5 ) ) ; System . out . println ( stirlingFactorial ( 6 ) ) ; System . out . println ( stirlingFactorial ( 7 ) ) ; } }