Program written in C++ to calculate factorial.
// ? 2017 TheFlyingKeyboard and released under MIT License // theflyingkeyboard.net #include <iostream> using namespace std; unsigned long long factorial(unsigned int n); int main(){ unsigned int n; cout << "Enter a number: "; cin >> n; cout << "Factorial of " << n << " is equal to " << factorial(n) << endl; return 0; } unsigned long long factorial(unsigned int n) { unsigned long long fact = 1; for(unsigned int i = 2; i <= n; i++){ fact *= i; } return fact; }
C++ Factorial