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, 22.06.2019 15:10
Consider a direct-mapped cache with 216 words in main memory. the cache has 16 blocks of 8 words each. it is a word-addressable computer (rather than a byte-addressable computer which we normally discuss). (a) how many blocks of main memory are there? (b) what is the format of a memory address as seen by the cache, that is, what are the sizes of the tag, cache block, and block offset fields (if they apply)? (c) to which cache block will the memory reference db6316 map?
Answers: 1
question
Computers and Technology, 23.06.2019 20:30
If an appliance consumes 500 w of power and is left on for 5 hours, how much energy is used over this time period? a. 2.5 kwh b. 25 kwh c. 250 kwh d. 2500 kwh
Answers: 1
question
Computers and Technology, 24.06.2019 00:00
Afashion designer wants to increase awareness about her brand. which network can she use and why she can use the blank to blank her products online. answers for the first blank: internet, extranet, or intranet answers for the second blank: market, design, and export
Answers: 1
question
Computers and Technology, 24.06.2019 12:00
An npn transistor is correctly biased and turned on if the a. base is negative. b. collector is negative. c. collector is positive with respect to the emitter and negative with respect to the base. d. collector is the most positive lead followed by the base.
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
Business, 03.05.2020 13:39
question
Mathematics, 03.05.2020 13:39
question
Mathematics, 03.05.2020 13:39
question
History, 03.05.2020 13:39
question
Biology, 03.05.2020 13:39
question
Mathematics, 03.05.2020 13:39
Questions on the website: 13722362