Answered step by step
Verified Expert Solution
Question
1 Approved Answer
4.12 Recursively Implement Pow Write a recursive function that will calculate a number raised to the n power. The function should support negative powers. There
4.12 Recursively Implement Pow Write a recursive function that will calculate a number raised to the n power. The function should support negative powers. There is a simple O(n) implementation, but the problem can be solved in O(log n). A slight modification to the O(n) algorithm can make it run in O(log n). The function must be recursive, no loops are allowed. Do not use the math library. Examples Input of 2.1000 raised to 3 will produce 9.26100 Input Do not read in input! There will be no input read in anymore. Going forward use the hard-coded input on the template and ensure the program works. There will be one compare output test based on the hard-coded input. The rest of the tests will be unit tests. Output Print the results from your function LAB ACTIVITY 4.12.1: Recursively Implement Pow 0730 Downloadable files main.cpp Download main.cpp Load default template... 1 // Include the necessary header files 2 double Pow(double num, int power) { /* Always start with the base case. If you were computing square root of a number there are two cases when you will always know what the result is. One case is when the power is 0. o vouw You must also deal with the case of n being negative. Remember 24-2 is 1/(242) 9 int main({ double num = 2.1; int power = 3; 19 11 douch // Call your function // Print your results from your function return 0; 17 }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started