Guest User

Untitled

a guest
Aug 28th, 2012
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.65 KB | None | 0 0
  1. /*
  2.  * File:   main.cpp
  3.  * Author: Vipar
  4.  *
  5.  * Created on August 28, 2012, 5:30 PM
  6.  */
  7.  
  8. #include <cstdlib>
  9. #include <iostream>
  10.  
  11. using namespace std;
  12.  
  13. uint base, power, result;
  14.  
  15. int exponent(uint b, uint e) {
  16.     if(e == 1) {
  17.         return b;
  18.     } else {
  19.         return b * exponent(b, (e - 1));
  20.     }
  21. }
  22.  
  23. int main() {
  24.     cout << "Welcome to the Exponent Calculator." << endl;
  25.     cout << "Please put a base (15 max): ";
  26.     cin >> base;
  27.     cout << "Please put an exponent (15 max): ";
  28.     cin >> power;
  29.     result = exponent(base, power);
  30.     cout << "The result of " << base << "^" << power << " is: " << result;
  31.    
  32.     return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment