Extend the quadratic equation solver program to handle cases where the roots are real, equal, or complex.
#include <stdio.h>
#include <math.h>int main() {
// Declare variables
float a, b, c, discriminant, root1, root2, realPart, imaginaryPart;// Input: Get coefficients from the user
printf(“Enter coefficients (a, b, c) of the quadratic equation (ax^2 + bx + c): “);
scanf(“%f %f %f”, &a, &b, &c);// Process: Calculate discriminant
discriminant = b * b – 4 * a * c;// Check the nature of roots
if (discriminant > 0) {
root1 = (-b + sqrt(discriminant)) / (2 * a);
root2 = (-b – sqrt(discriminant)) / (2 * a);
printf(“Roots are real and different: %.2f and %.2fn”, root1, root2);
} else if (discriminant == 0) {
root1 = root2 = -b / (2 * a);
printf(“Roots are real and equal: %.2fn”, root1);
} else {
realPart = -b / (2 * a);
imaginaryPart = sqrt(-discriminant) / (2 * a);
printf(“Roots are complex and different: %.2f + %.2fi and %.2f – %.2fin”, realPart, imaginaryPart, realPart, imaginaryPart);
}return 0; // Exit the program successfully
}