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
1. Design a circuit, utilizing set/reset coils where PB 1 starts Motor 1 and PB2 stops Motor 1. Pressing and releasing either pu
lianna [129]

Answer:

Circuit attached with explanation

Explanation:

Hi Dear,

A circuit is attached for your reference.

When you press "start" PB, the supply reaches the motor starter relay coil "M" that is also in parallel with the "start" PB which allows the motor to remain ON even when you release "start" PB as supply to relay coil is directly from supply "L" through "M".

To stop motor just press "stop" PB and the circuit breaks which de-energize the relay coil and the motor stops.

Hope this finds easy to you.

5 0
3 years ago
C++ - Green Crud Fibonacci programThe following program is to be written with a loop. You are to write this program three times
Fynjy0 [20]

Answer:

Below is the required code:

Explanation:

Using for loop

#include <iostream>

using namespace std;

int main()

{

    //Initial crud size

    int init = 0;

    int newCrud;

    int next=0;

    //Number of days to simulate

    int no_days;

    int day;

    cout << "Enter initial amount of green crud: ";

    cin >> newCrud;

    cout << "Enter number of days to simulate: ";

    cin >> no_days;

    for (day = 10; day<=no_days; day++)

    {

         if (day % 10 == 0)

         {

             next = newCrud + init;

         }

             newCrud = init;

             init = next;

    }

    if (no_days < 5)

    cout << "\nCrud reproduce only after 5 days minimum.Hence the current amount is "

    << newCrud << " pounds.";

    else

    cout << "On day " << no_days << " you have " << init

    << " pounds of green crud." << endl;

    cout << "\nWould you like to continue? (y or n): ";

    cin >> ans;

         return 0;

}

Output:

         Enter initial amount of green crud: 5

         Enter number of days to simulate: 220

    On day 220 you have 10485760 pounds of green crud.

Using while loop

Program:

#include <iostream>

using namespace std;

int main()

{

    char ans='y';

    while (ans == 'Y' || ans == 'y')

    {

         //Initial crud size

         int init = 0;

         int newCrud;

         int next=0;

         //Number of days to simulate

         int no_days;

         int day;

         cout << "Enter initial amount of green crud:

         ";

         cin >> newCrud;

         cout << "Enter number of days to simulate:

         ";

         cin >> no_days;

         for (day = 10; day<=no_days; day++)

         {

             if (day % 10 == 0)

             {

                  next = newCrud + init;

             }

                  newCrud = init;

                  init = next;

         }

         if (no_days < 5)

         cout << "\nCrud reproduce only after 5 days

         minimum.Hence the current amount is "

         << newCrud << " pounds.";

         else

         cout << "On day " << no_days << " you have "

         << init

         << " pounds of green crud." << endl;

         cout << "\nWould you like to continue? (y or

         n): ";

         cin >> ans;

    }

    return 0;

}

Output:

Enter initial amount of green crud: 5

Enter number of days to simulate: 220

On day 220 you have 10485760 pounds of green crud.

Would you like to continue? (y or n): y

Enter initial amount of green crud: 5

Enter number of days to simulate: 225

On day 225 you have 10485760 pounds of green crud.

Using do while loop

Program:

#include <iostream>

using namespace std;

int main()

{

    char ans;

    do

    {

         //Initial crud size

         int init = 0;

         int newCrud;

         int next=0;

         //Number of days to simulate

         int no_days;

         int day;

         cout << "Enter initial amount of green crud: ";

         cin >> newCrud;

         cout << "Enter number of days to simulate: ";

         cin >> no_days;

         for (day = 10; day<=no_days; day++)

         {

             if (day % 10 == 0)

             {

                  next = newCrud + init;

             }

                  newCrud = init;

                  init = next;

         }

         if (no_days < 5)

         cout << "\nCrud reproduce only after 5 days

         minimum.Hence the current amount is "

         << newCrud << " pounds.";

         else

         

         cout << "On day " << no_days << " you have " <<

         init << " pounds of green crud." << endl;

         cout << "\nWould you like to continue? (y or n):

         ";

         cin >> ans;

    } while (ans == 'Y' || ans == 'y');

    return 0;

}

Output:

Enter initial amount of green crud: 5

Enter number of days to simulate: 220

On day 220 you have 10485760 pounds of green crud.

Would you like to continue? (y or n): y

Enter initial amount of green crud: 5

Enter number of days to simulate: 225

On day 225 you have 10485760 pounds of green crud.

7 0
3 years ago
A large plate is fabricated from a steel alloy that has a plane strain fracture toughness of 55 MPa √m (50 ksi √in.). If, during
astra-53 [7]

Answer:

0.024 m = 24.07 mm

Explanation:

1) Notation

\sigma_c = tensile stress = 200 Mpa

K = plane strain fracture toughness= 55 Mpa\sqrt{m}

\lambda= length of a surface crack (Variable of interest)

2) Definition and Formulas

The Tensile strength is the ability of a material to withstand a pulling force. It is customarily measured in units (F/A), like the pressure. Is an important concept in engineering, especially in the fields of materials and structural engineering.

By definition we have the following formula for the tensile stress:

\sigma_c=\frac{K}{Y\sqrt{\pi\lambda}}   (1)

We are interested on the minimum length of a surface that will lead to a fracture, so we need to solve for \lambda

Multiplying both sides of equation (1) by Y\sqrt{\pi\lambda}

\sigma_c Y\sqrt{\pi\lambda}=K   (2)

Sequaring both sides of equation (2):

(\sigma_c Y\sqrt{\pi\lambda})^2=(K)^2  

\sigma^2_c Y^2 \pi\lambda=K^2   (3)

Dividing both sides by \sigma^2_c Y^2 \pi we got:

\lambda=\frac{1}{\pi}[\frac{K}{Y\sigma_c}]^2   (4)

Replacing the values into equation (4) we got:

\lambda=\frac{1}{\pi}[\frac{55 Mpa\sqrt{m}}{1.0(200Mpa)}]^2 =0.02407m

3) Final solution

So the minimum length of a surface crack that will lead to fracture, would be 24.07 mm or more.

7 0
4 years ago
The operating sequence to light the main burners on an intermittent pilot system is:______.
11111nata11111 [884]
The pilot valve and spark igniter are energized, the pilot flame is proved, and then the main gas valve is energized.
7 0
2 years ago
Tech A states that friction brakes lose energy as heat. Tech B states that a brake-by-wire system converts this energy into usef
hjlf
Tech A.......................
4 0
3 years ago
Other questions:
  • In some synchronizer applications, the clock frequency f is substituted for the parameter a in metastability MTBF calculations,
    12·1 answer
  • Which term defines the amount of mechanical work an engine can do per unit of heat energy it uses?
    5·1 answer
  • A shrinkage limit test is performed on a soil. The initial mass and volume of the soil are: V1=20.2cm^3 , while the final mass a
    15·1 answer
  • Please explain the theory of Hydrostatic Thrust on a plane Surface
    14·2 answers
  • 2. Write a Java program that generates a new string by concatenating the reversed substrings of even indexes and odd indexes sep
    10·1 answer
  • An operating gear box (transmission) has 350 hp at its input shaft while 250. hp are delivered to the output shaft. The gear box
    10·1 answer
  • Three possible career opportunities in embedded systems engineering
    11·1 answer
  • Please read and answer each question carefully.
    9·1 answer
  • Please answer fast. With full step by step solution.​
    14·1 answer
  • Computer system analyst advantage​
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!