Calculating Factorials using Stirling Approximation | CPP program for calculating factorial of a number using Stirling Approximation ; function for calculating factorial ; evaluating factorial using stirling approximation ; driver program
#include <bits/stdc++.h> NEW_LINE using namespace std ; long int stirlingFactorial ( int n ) { if ( n == 1 ) return 1 ; long int z ; z = sqrt ( 2 * 3.14 * n ) * pow ( ( n / e ) , n ) ; return z ; } int main ( ) { cout << stirlingFactorial ( 1 ) << endl ; cout << stirlingFactorial ( 2 ) << endl ; cout << stirlingFactorial ( 3 ) << endl ; cout << stirlingFactorial ( 4 ) << endl ; cout << stirlingFactorial ( 5 ) << endl ; cout << stirlingFactorial ( 6 ) << endl ; cout << stirlingFactorial ( 7 ) << endl ; return 0 ; }