1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
natka813 [3]
3 years ago
14

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 st

ands 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
Engineering
1 answer:
DanielleElmas [232]3 years ago
8 0

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.

You might be interested in
Nêu đặc điểm của tín hiệu PAM rời rạc dạng lưỡng cực NRZ, RZ
zhuklara [117]

Answer:

yes it is certainly good ice cream

4 0
3 years ago
Explain how feedback control is used to<br> adjust robotic movements.
LuckyWell [14K]

Answer:

Feedback control of arm movements using Neuro-Muscular Electrical Stimulation (NMES) combined with a lockable, passive exoskeleton for gravity compensation

6 0
2 years ago
How does a motion sensor work?
Ahat [919]

Answer:

A motion sensor uses one or multiple technologies to detect movement in an area. When a sensor detects motion, it sends a signal to your security systems control panel, which connects to your monitoring panel system. This alerts you and the monitoring center to a potential threat in your home.

Hope It Helps You................

3 0
3 years ago
If a 9V battery produces a current of 3 A through a load, what is the resistance of the load
Elden [556K]

3 ohms hope this helps :D ❤

7 0
3 years ago
Read 2 more answers
The cars of a roller-coaster ride have a speed of 19.0 km/h as they pass over the top of the circular track. Neglect any frictio
Dmitrij [34]

Complete Question

The cars of a roller-coaster ride have a speed of 19.0 km/h as they pass over the top of the circular track. Neglect any friction and calculate their speed v when they reach the horizontal bottom position. At the top position, the radius of the circular path of their mass centers is 21 m, and all six cars have the same mass.V = -18 m What is v?X km/h

Answer:

v=23.6m/s

Explanation:

Velocity v_c=18.0km/h

Radius r=21m

initial velocity uu=19=>5.27778

Generally the equation for Angle is mathematically given by

\theta=\frac{v_c}{2r}

\theta=\frac{18}{2*21}

\theta=0.45

\theta=25.7831 \textdegree

Generally

Height of mass

h=\frac{rsin\theta}{\theta}

h=\frac{21sin25.78}{0.45}

h=20.3m

Generally the equation for Work Energy is mathematically given by

0.5mv_0^2+mgh=0.5mv^2

Therefore

v=\sqrt{u^2+2gh}

v=\sqrt{=5.27778^2+2*9.81*20.3}

v=23.6m/s

3 0
3 years ago
Other questions:
  • Show how am MDP with a reward function R(s, a, s’) can be transformed into a different MDP with reward function R(s, a), such th
    15·1 answer
  • The textile industry has seen steady growth in the United States.<br> O True<br> O False
    12·1 answer
  • Find the sum and product of each of these pairs of numbers. Express your answers as a base 3 expansion. Hint: We can just add an
    5·1 answer
  • Question 9 of 25
    12·1 answer
  • A minor road intersects a major 4-lane divided road with a design speed of 50 mph and a median width of 12 ft. The intersection
    13·1 answer
  • On the position time curve, if the slope of a tangent at a point is positive, that means:
    6·2 answers
  • ¿Cómo llevan a cabo el lavado ropa?​
    8·1 answer
  • A logic circuit with 3 gates and 2 inputs. The circuit will be read from the final output to the inputs.
    9·1 answer
  • Pay attention to the following questions!
    14·1 answer
  • Vivian's Violins has sales of $326,000, contribution margin of $184,000 and fixed costs total $85,000. Vivian's Violins net oper
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!