#include <iostream>
using namespace std;
int power (int, int);
int main ()
{
int base, exp, result;
//obtain integer from user
cout<<"Enter the base value: ";
cin >>base;
cout<<"Enter the exponent value: ";
cin>>exp;
result = power(base, exp);
cout<<"The result is: "<< result << endl;
return 0;
}
// recursive definition
int power (int base, int exp)
{
// base case
if (exp==1)
return base * 1;
// recursive step
else if (exp >-1)
exp--;
return base * (power(base,exp));
}
Thursday, 24 January 2013
recursive exponents
08:26
ATEEK
No comments
0 comments:
Post a Comment