Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

4. (17) Write an algorithm for computing square roots of positive numbers. One way is to use a guess and check approach (i, e., guess

4. (17) Write an algorithm for computing square roots of positive numbers. One way is to use a guess and check approach (i, e., guess the square root of 17 is 4.1, check by squaring 4.1 [(4.1)(4.1) = 16.81], so 4.1 is too small; try 4.12 [(4.12)(4.12) = 16.9744] etc.). A programmable way of making guesses is to use Newtons method. Suppose x is the number we want the square root of and guess is the current guessed answer. The guess can be improved upon by using guess = (guess + (x/guess)) / 2 as the next guess. Write the design specifications and the program that implements Newtons method. Get the number to take the square root of (x) and the number of times to improve the guess from the user. Starting with an initial guess = x / 2, your program should loop the specified number of times applying Newtons method and report the final value of guess. You should also calculate the absolute value of difference (difference) between the square of your final guess [gues**2 and the value x to determine how close guess is to the square root of x. Output both guess and difference rounded to two decimal places to the screen with appropriate messages such as: The square root of, x, s approximately, round( guess,2) The difference between, x, and the square of, guess, is, round(difference,2)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions