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

Other questions on the subject: Computers and Technology

image
Computers and Technology, 23.06.2019 06:00, hilarydodard7099
Which statistical function in a spreadsheet you to see how far each number varies, on average, from the average value of the list?
Answers: 2
image
Computers and Technology, 23.06.2019 06:00, Disd112984
Which statement is true of web-based social media? a. they allow consumers to interact with and update content. b. they cannot be updated easily, as compared to print media. c. they are expensive to produce and maintain, as compared to print and television. d. they can exist independent of the internet.
Answers: 1
image
Computers and Technology, 23.06.2019 20:10, banna01man
Leo is a recruitment executive for a large company. he has identified new labor resource requirements in both the marketing and production departments. what should be his first step in recruiting candidates for the positions? a. conduct background checks of candidates b. make job offers c. arrange interviews d. conduct reference checks e. place job ads on job sites
Answers: 1
image
Computers and Technology, 23.06.2019 22:30, kayelynn003
How many points do i need before i can send a chat
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 in other subjects:

Konu
Mathematics, 16.06.2021 05:30
Konu
History, 16.06.2021 05:30
Konu
Mathematics, 16.06.2021 05:30