Solved

The Method Below Implements the Exponentiation Operation Recursively by Taking

Question 17

Multiple Choice

The method below implements the exponentiation operation recursively by taking advantage of the fact that, if the exponent n is even, then xn = (xn/2) 2. Select the expression that should be used to complete the method so that it computes the result correctly. public static double power(double base, double exponent)
{
If (exponent % 2 != 0) // if exponent is odd
{
Return base * power(base, exponent - 1) ;
}
Else if (exponent > 0)
{
Double temp = ________________________ ;
Return temp * temp;
}
Return base;
}


A) power(base, exponent / 2)
B) power(base, exponent / 2) * power(base, exponent / 2)
C) power(base, exponent / 2) + power(base, exponent / 2)
D) power(base, exponent) / 2

Correct Answer:

verifed

Verified

Unlock this answer now
Get Access to more Verified Answers free of charge

Related Questions