The divide-and-average algorithm


Question:

The divide-and-average algorithm

The divide-and-average algorithm for approximating the square root of any positive number a is as follows: Take any initial approximation x that is positive, and then find a new approximation by calculating the average of x and a/x, that is, (x + a/x)/2. Repeat this procedure with x replaced by this new approximation, stopping when x and a/x differ in absolute value by some specified error allowance, such as 0.00001. Write a program that reads values for x, a, and the small error allowance and then uses this divide-and-average algorithm to find the approximate square root of x. Execute the program with a=3 and error allowance=0.00001, and use the following initial approximationa: 1, 10, 0.01, and 100. Also execute the program with a=4, errow allowance=0.00001, and initial approximations 1 and 2.

Solution Preview :

Prepared by a verified Expert
Data Structure & Algorithms: The divide-and-average algorithm
Reference No:- TGS01936975

Now Priced at $20 (50% Discount)

Recommended (93%)

Rated (4.5/5)