Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I know how to do it from scratch, but I am having a lot of trouble with the code that my teacher has provided me
I know how to do it from scratch, but I am having a lot of trouble with the code that my teacher has provided me to use.
1.(40 pts) The Babylonian algorithm to compute the square root of a positive number nis as follows: a) Make a guess at the answer (you can pick n/2as initial guess) b) Computera n/guess c) Set guess (guess r)/2 d) Goback to step b) for as many iterations as necessary. The more times steps b) and c are repeated, the closer guess will become to the square root of n. Write a program that inputs a double for n from the console, iterates through the Babylonian algorithm five times, and outputs the answer as a double to two decimal places tothe console. Your program should also use the sqrt function from the camath library to calculate the actual square root of the user input and calculate a error as follows: Error abs(guess actual /actual 100. Use the abs function from the same library to calculate the absolute value of the difference and output it to two decimal places. Experiment with several inputs and starting values for the guess to test your program for correctness. Turn in console output text results that use n i5 as input, and make an initial guess at the answer as 2,2.5, and 3 (ie., show 3 different runs of your code) Use the shell below as your starting code and add in your code inside the function. Eincludekios tream> #includeStep 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