Question: C Program Assignment: Write an algorithm and program to compute e and compute the square root (). The calculation of the important mathematical constant e

C Program Assignment:

Write an algorithm and program to compute e and compute the square root (). The calculation of the important mathematical constant e and the square root () will be done as the sum of an infinite series:

e = 1/n! & S = xn+1 = 1/2(xn + S/xn)

n = 0 n = 0

where x0 is the initial guess

See https://en.wikipedia.org/wiki/E_(mathematical_constant) and

https://en.wikipedia.org/wiki/Methods_of_computing_square_roots for details. Use only the Babylonian method for the square root ().

Output: Output will include your computed value for e, the library expected value for e, the number of terms (iterations) it took to reach fifteen decimal-place accuracy, and the time (in nanoseconds) that it takes to compute the constant. Output will also include your computed value for the square root of a value input by the user, the expected value using sqrt(), the number of terms (iterations) it took to reach fifteen decimal-place accuracy, and the time (in nanoseconds) that it takes to compute the square root.

Each set of results above should be displayed so as to allow easy comparison of the computed and expected values. Labels should be included, where appropriate.

Input: Accept user input for the value for which the square root is sought. This number will be a real value, and for this assignment will be limited to a real value >= zero. Prompting and validation of the input is, of course, required.

Requirements: Use only material covered in the first four chapters of [K/R] and first five chapters of [D/D]. Style requirements as discussed in class expected.

Efficiency should always be considered. Alway choose the most appropriate loop/decision structures and variable/constant types. Functions should focus on a single task. Main() should be high-level tasks only.

The library should be used - see either text index or [K/R] pages 255-256 (Appendix B10) for more details. You may NOT use the math library functions sqrt() or exp() in your computations - directly or indirectly. Instead, use only the delta (difference) of your running computation to determine when to stop. No rounding is permitted.

Program must include (minimum) one function for each computation, in addition to the main program. Other functions developed (likely), as required. Test your program completely.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!