// // example of recursion: // // function to compute integer to non-negative power // // main (test) program repeatedly prompts for inputs // #include // precondition: e >= 0 // postcondition: returns b to the e power int exponent(const int b, const int e); // ---- main program ---- int main() { int b, e; char prompt[] = "Enter two integers, the second non-negative, " "or ctrl-D to end:\n"; cout << prompt; while (cin >> b >> e) { if (e < 0) cout << "Second number must be non-negative!\n"; else cout << b << " to the " << e << "-th power = " << exponent(b, e) << endl; cout << prompt; } return 0 ; } // ---- function definition ---- int exponent(const int b, const int e) { if (e == 0) return 1; else return b * exponent(b, e-1); }