#include #include using namespace std; int factorial(int i); int main() { //Output the product of the ints from 1 to 10 inclusive. cout << factorial(10) << "\n"; return EXIT_SUCCESS; } //Return the product of the ints from 1 to n inclusive. int factorial(int n) { if (n < 0) { cerr << "Can't take the factorial of a negative number.\n"; exit(EXIT_FAILURE); } if (n > 1) { //If the job is not finished yet, //Do only the last multiplication here; //call the function to do the remaining multiplications. return n * factorial(n - 1); } //Arrive here if the job is so small that it is already finished; //no multiplications are necessary. return 1; }