Question: The program below contains an incomplete recursive function raised _ to _ power ( ) . The function returns the value of the first parameter
The program below contains an incomplete recursive function raisedtopower
The function returns the value of the first parameter numberof type floatraised to
the value of the second parameter power of type int for all values of power greater
than or equal to
The algorithm used in this question to write a recursive function to raise a float
value number to a positive power uses repeated multiplication as follows:
numberpower if power
number x numberpower otherwise
In other words, number raised to power gives if power is ;
and otherwise numberpower can be calculated with the formula:
number x numberpower
#include using namespace std;
float raisedtopower
if power
cout
Error can't raise to a negative power
;
exit;
else if
return ;
else
return number raisedtopowernumber power ;
main
float answer raisedtopower;
cout answer;
return ;
b Using the fact that any value raised to the power of is complete the base case in line and
This question is based on question b in the written Assignment
The program in question of the written assignment, contains an incomplete recursive function raisedtopower This function returns the value of the first parameter number of type float raised to the value of the second parameter power of type int for all values of power greater than or equal to
Based on the fact that any value raised to the power of is the base case for this function is
Select one:
else if power
return ;
else if power
return ;
else if power
return ;
else if power
return number raisedtopowernumber power ;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
