Question: Define a function using recursion in C++ double power(double b, int n) that returns b to the power n. Assume b is nonzero. Hint: return
Define a function using recursion in C++ double power(double b, int n) that returns b to the power n. Assume b is nonzero. Hint: return the reciprocal of power(b,-n) when n < 0. When n > 0 use the fact that b^n = b*b^(n-1). For the base case use b^0= 1. The driver reads two number for b and n, then outputs power(b,n).
When I turned it in, it said my code was illegal:
double power(double b, int n)
{
if (n == 0){
return 1; }
else {
return b*power(b, n-1); }
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
