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
GMA MIG weiding is a
Dvinal [7]

Gas metal arc welding (GMAW), sometimes referred to by its subtypes metal inert gas (MIG) welding or metal active gas (MAG) welding, is a welding process in which an electric arc forms between a consumable MIG wire electrode and the workpiece metal(s), which heats the workpiece metal(s), causing them to melt and join.

6 0
3 years ago
For RTK to work, what do we need besides two or more receivers collecting data from a sufficient number of satellites simultaneo
Liula [17]

Answer:

phase measurement and the information content

Explanation:

The full form of RTK is Real Time Kinematic. It is used for satellite navigation technique to increase the precision of the position data that is derived from the positioning systems based on satellites like the NavIC, GPS, Galileo, BeiDou and GLONASS. It takes help of the measurements of phase of signal's carrier wave and also the information content of these signals and it also relies on the single interpolated virtual station in order to provide the real time corrections and provide correct and accurate information.

7 0
3 years ago
A 200 W vacuum cleaner is powered by an electric motor whose efficiency is 70%. (Note that the electric motor delivers 200 W of
Goshia [24]

Answer:

The rate at which this vacuum cleaner supply energy to the room when running is 285.71 Watts.

Explanation:

power efficiency of electric motor = 70% = 0.70

The power output of the vacuum cleaner =P_o= 200 W

The power output of the vacuum cleaner = P_i

Efficiency=\frac{P_o}{P_i}

0.70=\frac{200 W}{P_i}

P_i=\frac{200 W}{0.70}=285.71 W

The rate at which this vacuum cleaner supply energy to the room when running is 285.71 Watts.

5 0
3 years ago
- Scrap tire management is primarily regulated at the
kompoz [17]

Scrap tire management is primarily regulated at the state level.

3 0
3 years ago
Read 2 more answers
In highways the far left lane is usually the _____
Ivan
Fastest


(Known as the fast lane)
8 0
3 years ago
Read 2 more answers
Other questions:
  • Air is compressed adiabatically from p1 1 bar, T1 300 K to p2 15 bar, v2 0.1227 m3 /kg. The air is then cooled at constant volum
    13·1 answer
  • What parts does the block contain?
    5·2 answers
  • What is the rms current flowing through a light bulb that uses an average power of 60.0 60.0 W when it is plugged into a wall re
    12·1 answer
  • Given the following materials and their corresponding thermal conductivity values, list them in order from most conductive to le
    12·1 answer
  • The Review_c object has a lookup relationship up to the Job_Application_c object. The job_Application_c object has a master-deta
    7·1 answer
  • Air at 300 K and 100 kPa steadily flows into a hair dryer having electrical work input of 1500 W. Because of the size of the air
    6·2 answers
  • Determine the magnitude and the location of the hydrostatic force on the 2m by 4 m vertical rectangular gate shown in Figure P3.
    12·1 answer
  • 3. What is special about beryllium-copper alloy tools?
    6·2 answers
  • A person has driven a car 180 m in 40 seconds. What is the car’s speed?
    12·1 answer
  • I need help with this question
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!