subject

Write a program to solve a quadratic equation. The program should allow the user to enter the values for a, b, and c. If the discriminant is less than zero, a message should be displayed that the roots are imaginary; otherwise, the program should then proceed to calculate and display the two roots of the eqaution. (Note: Be certain to make use of the squareRoot () function that you developed in this chapter.) (In C language)

Hint: This should not be too hard. You need to get some numbers from the user, do some calculations, check if the discriminate is negative, then use the textbook author’s squareRoot function to finish up the calculations!

program 7.8:

// Function to calculate the absolute value of a number

#include

float absoluteValue(float x)

{

if (x < 0)

x = -x;

return (x);

}

// Function to compute the square root of a number

float squareRoot(float x)

{

const float espsilon = .00001;

float guess = 1.0;

while (absoluteValue(guess * guess - x) >= espsilon)

guess = (x / guess + guess) / 2.0;

return guess;

}

int main(void)

{

printf("squareRoot (2.0) = %f\n", squareRoot(2.0));

printf("squareRoot (144.0) = %f\n", squareRoot(144.0));

printf("SquareRoot (17.5) = %f\n", squareRoot(17.5));

return 0;

}

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 06:30
You are consulting for a beverage distributor who is interested in determining the benefits it could achieve from implementing new information systems. what will you advise as the first step?
Answers: 1
question
Computers and Technology, 24.06.2019 00:50
3. what is the output of the following statements? temporary object1; temporary object2("rectangle", 8.5, 5); temporary object3("circle", 6, 0); temporary object4("cylinder", 6, 3.5); cout < < fixed < < showpoint < < setprecision(2); object1.print(); object2.print(); object3.print(); object4.print(); object1.set("sphere", 4.5, 0); object1.print();
Answers: 1
question
Computers and Technology, 24.06.2019 22:00
Difference between ancient and modern mode of information transmission
Answers: 1
question
Computers and Technology, 25.06.2019 08:00
Is a major factor in the widespread use of global information systems
Answers: 1
You know the right answer?
Write a program to solve a quadratic equation. The program should allow the user to enter the values...
Questions
question
English, 22.04.2020 05:31
question
Spanish, 22.04.2020 05:31
question
History, 22.04.2020 05:31
question
Mathematics, 22.04.2020 05:31