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
For every 3 packages that Marcella wraps she uses 1/2 of a roll of wrapping paper if she uses 2 1/2 rolls of wrapping paper how
hram777 [196]
She wrapped 5 packages
6 0
3 years ago
Read 2 more answers
Write a program with total change amount as an integer input, and
AURORKA [14]

Answer:

amount = int(input())

#Check if input is less than 1

if amount<=0:

    print("No change")

else: #If otherwise

    #Convert amount to various coins

    dollar = int(amount/100) #Convert to dollar

    amount = amount % 100 #Get remainder after conversion

    quarter = int(amount/25) #Convert to quarters

    amount = amount % 25 #Get remainder after conversion

    dime = int(amount/10) #Convert to dimes

    amount = amount % 10 #Get remainder after conversion

    nickel = int(amount/5) #Convert to nickel

    penny = amount % 5 #Get remainder after conversion

    #Print results

    if dollar >= 1:

          if dollar == 1:

                print(str(dollar)+" Dollar")

          else:

                print(str(dollar)+" Dollars")

    if quarter >= 1:

          if quarter == 1:

                print(str(quarter)+" Quarter")

          else:

                print(str(quarter)+" Quarters")

    if dime >= 1:

          if dime == 1:

                print(str(dime)+" Dime")

          else:

                print(str(dime)+" Dimes")

    if nickel >= 1:

          if nickel == 1:

                print(str(nickel)+" Nickel")

          else:

                print(str(nickel)+" Nickels")

    if penny >= 1:

          if penny == 1:

                print(str(penny)+" Penny")

          else:

                print(str(penny)+" Pennies")

Explanation:

8 0
3 years ago
A man can swim at 4 ft/s in still water. He wishes to cross tje 40-ft wide river to point B, 30 ft downstream. If the river flow
iVinArrow [24]

Answer:

v \approx 4.472\,\frac{ft}{s}, t = 10\,s

Explanation:

Since man and river report constant speeds and velocities are mutually perpendicullar, the absolute speed of the man is calculated by the Pythagorean Theorem:

v = \sqrt{(4\,\frac{ft}{s} )^{2}+(2\,\frac{ft}{s} )^{2}}

v \approx 4.472\,\frac{ft}{s}

The required time to make the crossing is:

t = \frac{40\,ft}{4\,\frac{ft}{s} }

t = 10\,s

6 0
3 years ago
A single crystal of zinc is oriented for a tensile test such that its slip plane normal makes an angle of 65 degree with the ten
Crank

Answer:

a. 30°

b. 0.9MPa

Explanation:

The slip will occur along that direction for which the Schmid factor is maximum. The three possible slip directions are mentioned as 30°, 48°, 78°

The cosines for the possible λ values are given as

For 30°, cos 30 = 0.867

For 48°, cos 48 = 0.67

For 78°, cos 78 = 0.21

Among the three-calculated cosine values, the largest cos(λ) gives the favored slip direction

The maximum value of Schmid factor is 0.87. Thus, the most favored slip direction is 30° with the tensile axis.

The plastic deformation begins at a tensile stress of 2.5MPa. Also, the value of the angle between the slip plane normal and the tensile axis is mentioned as 65°

Thus, calculate the value of critical resolved shear stress for zinc:

From the expression for Schmid’s law:

τ = σ*cos(Φ)*cos(λ)

Substituting 2.5MPa for σ, 30° for λ and 65° for Φ

We obtain The critical resolved shear stress for zinc, τ = 0.9 MPa

4 0
3 years ago
An inductor is connected to a voltage source and it is found that it has a time constant, t. When a 10-ohm resistor is placed in
prisoha [69]

Answer:

A) 30 mH

B ) 10-ohm

Explanation:

resistor = 10-ohm

Inductor = 30mH ( l )

L = inductance

R = resistance

r = internal resistance

values of the original Inductors

Note : inductor = constant time (t)  case 1

inductor + 10-ohm resistor connected in series = constant time ( t/2) case2

inductor + 10-ohm resistor + 30 mH inductance in series = constant time (t) case3

<em>From the above cases</em>

case 1 = time constant ( t ) = L / R

case 2 = Req = R + r hence time constant  t / 2  = L / R + r  therefore

t = \frac{2L}{R+r}

case 3 = Leq = L + l , Req = R + r .  constant time ( t )

hence Z = \frac{L + l}{R + r} = t

A) Inductance

To calculate inductance equate case 1 to case 3

\frac{L}{R} = \frac{L + l}{R + r} =   L / 10 = (L + 30) / ( 10 + 10 )

= 20 L = 10 L + 300 mH

   10L = 300 m H

therefore L = 30 mH

B ) The internal resistance

equate case 1 to case 2

\frac{L}{R} = \frac{2L}{R + r}

R + r = 2 R  therefore  ( r = R )   therefore internal resistance = 10-ohm

6 0
3 years ago
Other questions:
  • The period of a pendulum T is assumed to depend only on the mass m, the length of the pendulum `, the acceleration due to gravit
    9·1 answer
  • Two infinite extent current sheets exist at z = −3.0 m and at z = +3.0 m. The top sheet has a uniform current
    11·1 answer
  • Discuss four (4) advantages of direct and indirect water supply system.
    5·2 answers
  • A 4-pole, 3-phase induction motor operates from a supply whose frequency is 60 Hz. calculate: 1- the speed at which the magnetic
    6·1 answer
  • What is stress corrosion cracking?
    9·1 answer
  • A fuel gas containing 45.00 mole% methane and the balance ethane is burned completely with pure oxygen at 25.00 degree C, and th
    11·1 answer
  • Practice finding the volume of a sphere.
    10·2 answers
  • F.R.E.E P.O.I.N.T.S F.R.E.E PO.I.N.T.S
    6·2 answers
  • Describe the first case where the power of synthesis was used to solve design problems.
    15·1 answer
  • When you multiply monomials with the same variables, you multiply the coefficients and add the exponents!
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!