#include #include //for exit, EXIT_SUCCESS, EXIT_FAILURE using namespace std; void factorial(int n); int main() { factorial(4); int i = 5; factorial(i); //Create a copy of i and pass it to the function. return EXIT_SUCCESS; } void factorial(int n) { if (n < 0) { cerr << "argument " << n << " can't be negative.\n"; exit(EXIT_FAILURE); //outside of main, exit instead of return } int f = 1; for (int i = 1; i <= n; ++i) { f *= i; } cout << "The factorial of " << n << " is " << f << ".\n"; }