Exponentional recursive function

Hello!

I need some help writing a function,that calculates the value x^y,when x and y>0.

I´ve wrote a function that calculates the value with the base 10,but not so certain how i should proceed with user inputed base.

This is probably quite simple,any help would be appreciated!

my recursive function with the base 10:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
int exp(int x)
{
	if(x==0)
	{
		return 1;
	}
	else
	{
		return 10*exp(x-1);
	}
}
int main()
{
	int y=exp(3);

	cout<<y<<endl;
}
Last edited on
You are going in the right direction :)
HINT: Just pass another variable ( the base ) and change that return a bit, and there you have it.
Take in the base as a parameter, and, instead of doing 10*exp(x-1) , do base*exp(x-1). Also, exp may be easily confused with the function ex. Consider changing the function name.
Thanks,got it to work:)
Topic archived. No new replies allowed.