hey guys im studying about recursion by myself and i want to make a recursive function that prompts the user to input the base and exponent and generate the final answer . i have no ideas how to do it can anyone help me?
#include<iostream>
usingnamespace std;
int recursive(int x, int y);
int main()
{
/*i did the program iterate form first to find ways how to solve it recursively but still its useless i dont know where to start */
/*int total=1;
int y, x;
cout<<"Enter base : ";
cin>>x;
cout<<"Enter exponent : ";
cin>>y;
for(int i=0; i<y; i++)
{
total*=x;
}
cout<<x<<"^"<<y<<" = "<<total;*/
}
int recursive(int x, int y)
{
}
First a design consideration. You are dealing with exponents, exponents get large and generally deal with positive numbers. You should therefore use a variable type that stores large positive numbers. To keep it simple, since you are a self professed beginner, we'll ignore negative exponents and rule out floats. I recommend an 'unsigned int' for your data types.