(code blocks C programming) Write a program that determines whether a quadratic
ID: 1715200 • Letter: #
Question
(code blocks C programming) Write a program 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.The roots of the equation are found using the quadratic equation: 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).Call a function to calculate the discriminant D. Use conditional statements to display the type of roots (one real, two real, or imaginary)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.At the end of your program, offer the user the option to run again or exit.
Two Real Roots, D>0
One Real Root, D=0
Two Imaginary Roots, D<0
Explanation / Answer
#include #include #include void main() { float a, b, c, d, root1, root2; clrscr(); printf("Enter the values of a, b, c "); scanf("%f%f%f", &a, &b, &c); if(a == 0 || b == 0 || c == 0) { printf("Error: Roots can't be determined"); } else { d = (b * b) - (4.0 * a * c); if(d > 0.00) { printf("Roots are real and distinct "); root1 = -b + sqrt(d) / (2.0 * a); root2 = -b - sqrt(d) / (2.0 * a); printf("Root1 = %f Root2 = %f", root1, root2); } else if (d < 0.00) { printf("Roots are imaginary"); root1 = -b / (2.0 * a) ; root2 = sqrt(abs(d)) / (2.0 * a); printf("Root1 = %f +i %f ", root1, root2); printf("Root2 = %f -i %f ", root1, root2); } else if (d == 0.00) { printf("Roots are real and equal "); root1 = -b / (2.0 * a); root2 = root1; printf("Root1 = %f ", root1); printf("Root2 = %f ", root2); } } getch(); }Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.