/* fact.cpp * Computes the factorial of a number * * The factorial of a number N is denoted by N!. * N! = 1 * 2 * (N - 1) * N * * By definition 0! is 1 */ #include #include using namespace std; long double factorial(int fact); int main(int argc, char *argv[]) { int fact; cout << "Enter a non-negative number less than 30" << endl; cin >> fact; if(fact < 0 || fact > 30) { cout << "Value out of Range" << endl; system("PAUSE"); exit(1); } cout << fixed << factorial(fact) << endl; system("PAUSE"); return EXIT_SUCCESS; } long double factorial(int fact){ if(0 == fact){ return 1; } long double product = 1; for(int i = 1; i <= fact; i++){ product *= i; } return product; }