in c the square root of a number N can be approximated by repeated calculation using the formula NG = 0.5(LG + N/LG) where NG stands for next guess and LG stands for last guess. Write a function that calculates the square root of a number using this method. The initial guess will be the starting value of LG. The program will com- pute a value for NG using the formula given. The difference between NG and LG is checked to see whether these two guesses are almost identical. If they are, NG is accepted as the square root; otherwise, the next guess (NG) becomes the last guess (LG) and the process is repeated (another value is computed for NG, the difference is checked, and so on). The loop should be repeated until the difference is less than 0. 005. Use an initial guess of 1. 0. Write a driver function and test your square root function for the numbers 4, 120. 5, 88, 36.01, 10,000, and 0. 25
PLEASE İN C PROGRAMMİNG

Answers

Answer 1

Answer:

Following are the program to the given question:

#include <stdio.h>//header file

double square_root(double N, double initialGuess)//defining a method square_root that takes two variable in parameters

{

double NG, LG = initialGuess,diff;//defining double variable

while(1)//use loop to calculate square root value

{

NG = 0.5 * (LG + N / LG);//using given formula

diff = NG - LG;//calculating difference

if(diff < 0)//use if to check difference is less than 0

diff = -diff;//decreaing difference

if(diff < 0.005)//use if that check difference is less than 0.005

break;//using break keyword  

else//defining else block

{

LG = NG;//holding value

}

}

return NG;//return value

}

int main()//defining main method

{

double ans, n,initialguess = 1.0;//defining double variable

n = 4;//use n to hold value

ans = square_root(n, initialguess);//calculating the square root value and print its value

printf("square_root(%lf) = %lf \n", n, ans);//print calculated value with number

n = 120.5;//use n to hold value

ans = square_root(n, initialguess);//calculating the square root value and print its value

printf("square_root(%lf) = %lf \n", n, ans);//print calculated value with number

n = 36.01;//use n to hold value

ans = square_root(n, initialguess);//calculating the square root value and print its value

printf("square_root(%lf) = %lf \n", n, ans);//print calculated value with number

n = 0.25;//use n to hold value

ans = square_root(n, initialguess);//calculating the square root value and print its value

printf("square_root(%lf) = %lf \n", n, ans);//print calculated value with number

printf("\nEnter a number: ");//print message

scanf("%lf", &n);//input value

ans = square_root(n, initialguess);//calculating the square root value and print its value

printf("square_root(%lf) = %lf \n", n, ans);//print calculated value with number

}

Output:

Please find the attachment file.

Explanation:

In this code, a method "square_root" is declared that takes two variable "N, initialGuess" in its parameters, inside the method a three double variable is declared.It uses the given formula and uses the diff variable to hold its value and uses two if to check its value is less than 0 and 0.005 and return its calculated value.In the main method, three double variables are declared that use the "n" to hold value and "ans" to call the method that holds its value and print its value.
In C The Square Root Of A Number N Can Be Approximated By Repeated Calculation Using The Formula NG =

Related Questions

"All data types are keywords but all keywords are not data types", justify this statement.​

Answers

Hey Mate Here Is Your Answer

Keywords Are Reserved Words Which Are Not Use As Normal Cases But Used For Special Purpose In Our Program whereas, Data Type Tells The Compiler And Interpreter How The Program Is Going To Be Executed And Can Be Used At Every Cases.

Hope This Helps You ❤️

Based on how they are stored in the computer, the types produced by these keywords can be categorized into two families, integer types and floating-point types.

What is the relation between data and keyword?

Bit, byte, and word are terminology that can be used to refer to either memory or data storage units in computers.

The main distinction between text fields and keyword fields is that text fields are examined during indexing, whereas keyword fields are not.

This means that while keyword fields are indexed exactly as is, text fields are split down into their constituent phrases at indexing to allow for partial matching.

A word or collection of words that an Internet user enters into a search engine or search bar to conduct a search is referred to as a keyword in the context of digital marketing.

Therefore, All data types are keywords, but all keywords are not data types.

Learn more about data and keywords here:

https://brainly.com/question/9588905

#SPJ2

SN1 reactions usually proceed with ________. A) equal amounts of inversion and retention at the center undergoing substitution B) slightly more inversion than retention at the center undergoing substitution C) slightly more retention then inversion at the center undergoing substitution D) complete inversion at the center undergoing substitution E) complete retention at the center undergoing substitution complete retention at the center undergoing substitution slightly more retention then inversion at the center undergoing substitution complete inversion at the center undergoing substitution equal amounts of inversion and retention at the center undergoing substitution slightly more inversion than retention at the center undergoing substitution

Answers

Answer:

equal amounts of inversion and retention at the center undergoing substitution

Explanation:

In an SN1 reaction, the rate determining step is the formation of a carbonation which is flat and planar.

This means that both faces of the carbo cation are equally available for attack by the nucleophile.

Attack on either of the faces may occur equally thereby yielding a racemic mixture.

Other Questions
Que diferecias se observan en las distintas banderas ? Gracias What was the goal of Asian American activists who participated in the strike at San Francisco State College?to overthrow Earl Warrento establish ethnic studies programsto raise money for the athletics programto recruit membership in La Raza Unida Need help ASAP thanks Can someone help me with this question please.. what could be their motivation in doing so, and most importantly, what is the impact of these graffiti to the viewing public why is density of population low in province No.6 HELP FOR MY ENGLISH TEST C1 thanks. 1 Ken apologised for ........ the office document.1 having been lost2 having lost3 being lost4 lose2 There is no point ........ over your mistake. It won't change anything.O to cryO in cryingO to have criedO to be crying3 Tim's mum made him...... his messy bedroom. 1 tidy 2 tidying 3 to tidy 4 to have tidied 4 Jeff went to bed late and is too sleepy.......... properly 1 to function 2 functioning 3 to have functioned 4 to be functioning 5. You...... Mark at work. He's gone on holiday. 1 can't have seen 2 needn't have seen3 might not have seen4 mustn't have seen 6 my leg is healed and I....... a cast anymore. 1. mustn't wear 2 shouldn't wear 3 don't have to wear4 can't wear 7Only the manager....... enter the building without a pass. No one else. 1 is sure to 2 is bound to 3 is allowed to 4 is supposed to8 Tom suddenly left the office without...... anyone1 to inform 2 to have informed 3 to be informing 4 informing An explanation of what South African laws are on ethical research standards Writing a Narrative Essay about Being Judged I need help please anyone I need help finding the solution 2. The cost of oranges varies directly with the total mass bought. 2 kg of oranges costs $4.50. Describe the relationship between cost and mass in words. You may want to calculate a unit rate first. Where do tectonic activities, such as earthquakes or volcanic eruptions, tend to occur?A. near plate boundariesB. near all mountainsC. in the center of continentsD. only on the ocean floor Which economic effect does a central bank hope to achieve by buying backlarge amounts of treasury securities?A. It hopes to raise interest rates for private lenders.B. It hopes to discourage companies from hiring workers.C. It hopes to make more money available for loans.D. It hopes to reduce the overall amount of economic activity. 2(x+3)=x-4please help me Mary makes 10 pies and 20 cakes a day and her opportunity cost of producing a cake is 2 pies. Tim makes 20 pies and 10 cakes a day and his opportunity cost of producing a cake is 4 pies. If Mary and Tim specialize in the good in which they have a comparative advantage, _________A. Mary produces only cakes while Tim produces only pies B. Mary produces only pies C. Tim produces both pies and cakes D. Tim produces only cakes while Mary produces only pies The newspaper in Haventown had a circulation of 80,000 papers in the year 2000. In 2010, the circulation was 50,000. With x=0 representing the year 2000, the graph below models this scenario.A coordinate plane showing Newspaper Circulation, Years Since 2000 on the x-axis and Circulation on the y-axis. A line starting at (0, 80,000), passing through a point at (10, 50,000) and ending at (18, 25,000).What number will complete the point-slope equation that models this scenario?y50,000=[_______](x10)3,0002,0002,0003,000 According to Madison, what must a government do to limit the influence of a powerful faction?a) control the influence factions have on governmentb) depend on only enlightened legislators serving in governmentc) raise taxes on factions to lessen their powerd) limit the ability to form factions De 1.620 trabajadores de una empresa textil 7/9 trabajan en confeccion y el resto en tareas administrativas. cuantos trabajadores trabajan en confeccion? Solve the system of equations by substitution. Simplify your answer. Write thesolution as an ordered pair.y= 3x - 133x + 2y = 19