Simple C++ program to calculate Stirling approximation (factorial approximation).
#define _USE_MATH_DEFINES #include <iostream> #include <math.h> // 2018 TheFlyingKeyboard and released under MIT License // theflyingkeyboard.net int main() { const double c = 2.506628274631000502415765284811045253006986740609938316629; int n = 1; double stirling = 1; std::cout << "Enter n" << std::endl; std::cin >> n; stirling = c * sqrt(n) * pow(n / M_E, n); std::cout << "Striling approximation of " << n << "! is equal to " << stirling << ", rounded " << round(stirling) << std::endl; int a; std::cin >> a; return 0; }
C++ Stirling Approximation