// // Program name: factorial_function // Author: B. Massingill // // This program defines and tests a factorial function. // // Input, output: see program text // #include // // Function name: factorial // // Precondition: // n is positive // Postcondition: // return value is n factorial // // Note that we don't say what this function does if n is not positive. // So to use this function appropriately, you should be sure to // call it only with positive n. // int factorial(int n); // // Main program // int main() { int n; cout << "Enter a positive integer\n"; cin >> n; if (n > 0) cout << n << " factorial is " << factorial(n) << endl; else cout << "Not a positive integer\n"; return 0; } // code for factorial function (see above for function documentation) int factorial(int n) { int valueToReturn = 1 ; for (int i = 2; i <= n; i++) valueToReturn *= i; return valueToReturn; }