suppose that take input as base=2 and power=3.We enter function power(),double power(double a,double b)
a=2 and b=3
if(b==0) false
else
return (a*power(a,b-1)); i.e. return (2*power(2,3-1)); i.e. return (2*power(2,2));
A recursive call[power(2,2)]
if(e==0) false
else
return (a*power(a,b-1)); i.e. return (2*power(2,2-1)); i.e. return (2*power(2,1));
A recursive call[power(2,1)]
if(e==0) false
else
return (a*power(a,b-1)); i.e. return (2*power(2,1-1)); i.e. return (2*power(2,0));
A recursive call[power(2,0)]
if(e==0) true
return 1
So now we will have
1 … power(2,0)
2*1 = 2 … power(2,1)
2*2 = 4 … power(2,2)
2*4 = 8 …power(2,3) ….final answer
It looks like you're new here. If you want to get involved, click one of these buttons!