Levels Tought:
Elementary,Middle School,High School,College,University,PHD
Teaching Since: | May 2017 |
Last Sign in: | 307 Weeks Ago, 2 Days Ago |
Questions Answered: | 66690 |
Tutorials Posted: | 66688 |
MCS,PHD
Argosy University/ Phoniex University/
Nov-2005 - Oct-2011
Professor
Phoniex University
Oct-2001 - Nov-2016
Write a C program using Code::Blocks that determines whether a quadratic equation has one real root, two real roots, or imaginary roots. Then, if the roots are real, display the roots of the quadratic equation. A quadratic equation is of the form ax^2 + bx + c = 0. The discriminant of the equation is D = b^2 - 4ac. If D > 0, then there are two real roots. If D == 0, then there is one real root, and if D < 0, then there are two imaginary roots.
Procedure
1. Include the usual (detailed) comment block including program name, author, date, inputs, outputs and description, followed by your preprocessor directives.
2. After declaring your variables, explain the program to the user by printing a description to the monitor. Â
3. Call a function that prompts the user for each of the values of the coefficients a, b, and c for the quadratic equation and returns the value entered, with error checking for a valid input (scanf returned a value).
4. Call a function to calculate the discriminant D. Â
5. Use conditional statements to display the type of roots (one real, two real, or imaginary)
6. Depending on the type of roots, use the appropriate form of the quadratic equation to calculate the roots of the equation and display them. For imaginary roots, you will need to calculate the real and imaginary parts separately and print them with the imaginary number i as part of the format.
7. At the end of your program, offer the user the option to run again or exit.
Test Equations Â
a) 2x^2+8x+8=0Â Â (One real root -> -2.0)
b) -5x^2+3x-4=0Â Â (Two imaginary roots)
c) -2x^2+7x+4=0Â Â (Two real roots -> -0.5, 4.0)
Hel-----------lo -----------Sir-----------/Ma-----------dam-----------Tha-----------nk -----------You----------- fo-----------r u-----------sin-----------g o-----------ur -----------web-----------sit-----------e a-----------nd -----------acq-----------uis-----------iti-----------on -----------of -----------my -----------pos-----------ted----------- so-----------lut-----------ion-----------.Pl-----------eas-----------e p-----------ing----------- me----------- on-----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be-----------