Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program computes the square root of a number entered by the user. Note: while there is a math function in the cmath library

Write a program computes the square root of a number entered by the user.
Note: while there is a math function in the cmath library that computes a square root, do not use that function for this lab. Instead, write your own code to compute the square root using the algorithm described below.
The idea behind the algorithm is to repeatedly compute estimates of the squrare root until the desired accuracy is obtained. Each new estimate will be closer to the actual value of the square root. If x is the number for which the square root will be computed, the next estimate is (previous estimate +(x / previous estimate))/2.
(To understand why this algorithm works, see Methods of Computing Square Roots.)
The pseudocode for the algorithm is:
Get the number for which to compute the square root from the user (x)
Set the estimate of the square root to x /2.0(initial estimate)
As long the difference between the computed square root and the previously computed square root is less than the desired accuracy:
Set the previous estimate to the current estimate
Compute the next estimate: (previous estimate +(x / previous estimate))/2
Output the final estimated square root to the screen with 6 decimal places after the decimal point.

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 C# And Databases

Authors: Philip Conrod, Lou Tylee

16th Edition

1951077083, 978-1951077082

More Books

Students also viewed these Databases questions