Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdlib>
- #include <iostream>
- using namespace std;
- uint base, power, result;
- uint exponent(uint b, uint e) {
- if(e == 1) {
- return b;
- } else {
- return b * exponent(b, (e - 1));
- }
- }
- int main() {
- cout << "Welcome to the Exponent Calculator." << endl;
- cout << "Please put a base: ";
- cin >> base;
- cout << "Please put an exponent : ";
- cin >> power;
- result = exponent(base, power);
- cout << "The result of " << base << "^" << power << " is: " << result;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement