Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribed

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> #include

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

Visual Basic Net Database Programming

Authors: Rod Stephens

1st Edition

0789726815, 978-0789726810

More Books

Students also viewed these Databases questions

Question

2. How were various roles filled?

Answered: 1 week ago