Define a recursive method power( ) which takes two arguments,1st base & 2nd exponent and returns the result accordingly. Example, power(2, 3) which returns 8.
#include <iostream>
using namespace std;
int Power(int base, int base_power)
{
if (base_power != 0)
return (base*Power(base, base_power-1));
else
return 1;
}
int main()
{
int base, base_power, answer;
cout << "ENTER BASE NUMBER\t\t\t= ";
cin >> base;
cout << "ENTER POWER NUMBER (POSITIVE INTEGER) = ";
cin >> base_power;
answer = Power(base, base_power);
cout<<endl;
cout << base << "^" << base_power << " = " << answer;
return 0;
}