// Ch. 18 Demo Program #1 // Mr. Minich // Purpose - to illustrate the use of recursive functions #include<iostream> using namespace std; int factorial(int); int power(int, int); int main() { int base = 0; // user input, base int exponent = 0; // user input, exponent cout << "Enter the base: "; cin >> base; cout << "Enter the exponent: "; cin >> exponent; cout << endl << base << " to the " << exponent << " power is " << power(base, exponent) << endl; cout << "The factorial of " << base << " is: " << factorial(base) << endl << endl; return 0; }// end of main int factorial(int base) { // precondition: 0 <= base if (base != 0) { return (base * factorial(base - 1)); } else { return 1; } } // end of factorial int power(int base, int exponent) { // precondition: 0 <= exponent if (exponent != 0) { return (base * power(base, exponent - 1)); } else { return 1; } } // end of power