Levels Tought:
Elementary,Middle School,High School,College,University,PHD
Teaching Since: | Jul 2017 |
Last Sign in: | 211 Weeks Ago, 3 Days Ago |
Questions Answered: | 15833 |
Tutorials Posted: | 15827 |
MBA,PHD, Juris Doctor
Strayer,Devery,Harvard University
Mar-1995 - Mar-2002
Manager Planning
WalMart
Mar-2001 - Feb-2009
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 <math.h> 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:
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 <time.h> 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.
----------- Â ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly