Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write the following program in C: Program 8: homebrew math functions For this assignment, write some functions that duplicate those in the standard math library
Write the following program in C:
Program 8: homebrew math functions For this assignment, write some functions that duplicate those in the standard math library Don't use any standard math library functions in your functions. Use standard math functions only in main for testing ZERO 1. Write the function double myexp (double x); that returns ewhere e is the base of natural logarithms, 2.718281828... Do this by summing the terms of the power series, r2 r 7l n! Continue looping until the absolute value of the current term is close to zero. For example myexp( 2.4)1 2.4 2.4/2 +2.43/6 2.44/242.45/1202.46/720 * 11.023 The correct way to do this is to make use of the fact that each term of the series is equal to the previous term times x for that term's n. Don't calculate n! for each term. Recall that n! blows up very quickly and calculating it by itself will lead to problems Initialize a sum (to one) and a current term (to one) and write a loop body that computes the next term based on the current term and adds it to the current sum. Then the new term becomes the current term. Write the function to be side-effect free (no I/O, no globals) The function takes a parameter of type double and returns a value of type double. Within the function body use type double for the term and the sum. The loop counter should, of course, be an int. Assume that x is in the range -25 to +25 or so, although ideally it can be any real valueStep 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