Complete the recursive function raisetopower(). ex: if userbase is 2 and userexponent is 4, then raisedvalue is assigned with 16
(i.e. 2^4). note: this example is for practicing recursion; a non-recursive function, or using the built-in function pow(), would be more common.
1 answer:
Using the property that x^n is x*x^(n-1) you can write a recursive function:
double raisetopower(double x, int n)
{
if (n <= 0) {
return 1.0;
}
return x*raisetopower(x, n - 1);
}
Note that this crude implementation does not deal with negative or fractional exponents. But it shows recursion.
You might be interested in
Indents? Double Space? one of those
Answer:
It responds to a specific set of instructions in a well-defined manner. It can execute a prerecorded list of instructions (a program).
A) <span>unauthorized duplication of software </span>
Answer: AES encryption
802.1x
Explanation: