Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(20 pts) Given an integer, a, one can approximate its square root as follows: start with a very rough guess about the answer, x0, and

image text in transcribed

(20 pts) Given an integer, a, one can approximate its square root as follows: start with a very rough guess about the answer, x0, and then improve the guess using the following formula: x1=(x0+a/x0)/2 For example, if we want to find the square root of 9 , and we start with x0=6, then x1=(6+9/6)/2=15/4=3.75, which is closer. We can repeat the procedure, using x1 to calculate x2, and so on. In this case, x2=3.075 and x3=3.00091. So that is converging very quickly on the right answer (which is 3 ). Write a C program (in file q1.c) that takes an integer as a command line argument and prints an approximation (as a float) of the square root of the argument, using this algorithm. You should not use the sqrt() function from the math.h library. As your initial guess, use a/2. Your program should iterate until it gets two consecutive estimates that differ by less than 0.0001; in other words, until the absolute value of xnxn1 is less than 0.001. You can use the built-in fabs() function from the math.h library to calculate the absolute value

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_2

Step: 3

blur-text-image_3

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

Seven NoSQL Databases In A Week Get Up And Running With The Fundamentals And Functionalities Of Seven Of The Most Popular NoSQL Databases

Authors: Aaron Ploetz ,Devram Kandhare ,Sudarshan Kadambi ,Xun Wu

1st Edition

1787288862, 978-1787288867

More Books

Students also viewed these Databases questions