Heron method to locate sqaure root of a number


Assignment:

Heron method to locate sqaure root of a number

The Heron Method for approximating the square root of a number states that if x is a guess for the square root of n then a better guess x' is:

x' = [x + (n/x)] / 2

Naturally this process can be repeated using x' in place of x the next time through the loop. The loop can stop when the difference between the previous and next guesses is small enough.

A programmer wrote the following code to implement the Heron Method to locate the square root of any number:

function heronSqrt(n)
{
var DELTA = 1.0E-10;
var nextGuess;
var prevGuess = n;
do
{
nextGuess = (prevGuess + (n/prevGuess))/2.0;
prevGuess = nextGuess;
} while (nextGuess-prevGuess > DELTA)
return nextGuess;
}

However, the code does not work properly. Fix the program so that it works. Also list a set of test cases that will thoroughly exercise the Heron Method code above.

Review the attachment:

Attachment:- Debug Function.rar

Solution Preview :

Prepared by a verified Expert
Other Subject: Heron method to locate sqaure root of a number
Reference No:- TGS01936592

Now Priced at $20 (50% Discount)

Recommended (90%)

Rated (4.3/5)