Question: Write a C program, to solve the quadratic equation a x 2 + b x + c = 0 of given coefficients a, b and

Write a C program,  to solve the quadratic equation a x2 + b x + c = 0 of given coefficients a, b and c. When running the program, it prompts for the input of coefficients a,b,c as floating numbers. After inputting three floating numbers, it computes and prints out the solutions, then prompts for another round of input. Your program will quit when getting input 0,0,0. Your program should handle four situations: (1) a=0, not a quadratic equation; (2) b2 - 4ac = 0, the equation has two equal roots; (3) b2 - 4ac < 0, the equation has complex roots; (4) b2 - 4ac > 0, the equation has distinct real roots. Your program should be robust for invalid inputs.

output:

Please enter the coefficients a,b,c:
1,2,1
The equation has two equal real roots:
-1.000000
Please enter the coefficients a,b,c:
1,2,2
The equation has two complex roots:
-1.000000+1.000000i -1.000000-1.000000i
Please enter the coefficients a,b,c:
2,6,1
The equation has two distinct real roots:
-0.177124 -2.822875
Please enter the coefficients a,b,c:
a,b,c
Invalid input
Please enter the coefficients a,b,c:
1,2
Invalid input
Please enter the coefficients a,b,c:
0,1,2
not a quadratic equation
Please enter the coefficients a,b,c:
0,0,0

Step by Step Solution

3.34 Rating (151 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

include include int main float a b c while 1 printfPlease enter the coefficients a b c ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Computer Network Questions!