Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Code in c CS1050-Lab 4 Spring 2019 Concepts to Practice .Recursion . math.h .Extend Prelab 4 Description For the lab assignment, Power function you write

Code in c image text in transcribed
image text in transcribed
image text in transcribed
CS1050-Lab 4 Spring 2019 Concepts to Practice .Recursion . math.h .Extend Prelab 4 Description For the lab assignment, Power function you write func you are to write a recursive function to calculate Power (exponentiation). The will ralse a given double type number to a positive integer power. This runction must use recursion to achieve its goal. The function must check that the power re greater than zero and less than or equal to 100. If the power is not in the given range, the fu compare the result of your Power function with the result of the pow() function from math.h in the Standard C Library. If the results In order to test your Power function, you must also write a function called DoTest. The DoTest function will are the same. DoTest should print a success message. if the results are not the same, DoTest should print a fail message. The main() function in your program should look exactly like this int main(void) printf(* Welcome to the Power Calculation Test Program *Inin") DoTest (1,1) DoTest (2,2); DoTest (1.e5,10); DoTest(1.e5,10e) DoTest (-1,2); DoTest (-1.05,10) DoTest (5,101); DoTest(5.3,e) DoTest (5.7,-1); DOLL Functions You Must Write You may write any functions you wish to implement this program, in addition to the following functions However, you must implement the following functions: e base, int exponent)-This function raises base to the power exponent only return a correct result if the exponent is in the range 1 If the exponent is not in range, it should just assume the exponent should be1 . dou ble Powerfdoubl and returns the result. It should through 100. and return base. The calculation must be done using recursion void DoTest(double base, int exponent)- This function checks whether the result of the Power function is the same as the result of the built-in pow() function. If it is, it prints a success message. If not, it prints a failure message. .int main(void) - Of course, you need to write a main), but l actually wrote it for you above Hints You should print double numbers with %lf as the formatter . Some of the tests should fail Sample Output (bold and underline shows user input) JmR@jmr surfaces JimR@jimrsurface:s /a out ** Welcome to the Power Calculation Test Program compile x-lab4.c * Test Power(1.000000,1) Succeeded!* * Test Power (2.e0000,2) Succeeded! * * Test Power (1.058000,10) Succeeded! * Test Power (1.858880,100) Succeeded! *Test Power (-1.000000,2) Succeeded! * Test Power (-1.058080,10) Succeeded! * Test Power (5.00e000,101) Failed. * Test Power(5.388000,0) Failed. * * Test Power(5.7808ee,-1) Failed. * DOLL Guidelines for Grading Lab 4 40 Points Possible (+6 bonus points) General If your program does not compile, or produce any input/output source code is commented out then your lab will receive a grade of NO because most of the POINTS. For partial program must not only compile but also produce some valid L/O that meets the latb specifications. 7 points: Header, correct variable type assignment and general coding style. 5 points: PowerO function generally correct and uses recursion. 5 points: DoTestO function generally correct, comparing Power0 to powo. 5 points: All 9 tests written in main) as shown in instructions. 18 points: First 6 tests pass properly (3 points each) BONUS (6 points) 6 points: Last 3 tests fail properly (2 points each)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Administrator Limited Edition

Authors: Martif Way

1st Edition

B0CGG89N8Z

More Books

Students also viewed these Databases questions