/* Program to find the roots of a quadratic equation */ /* Problem 4 */ #include #include #include main() { float a,b,c; float D; float x1, x2; clrscr(); printf("Enter the coefficient of x^2 i.e. a : "); scanf("%f",&a); printf("Now enter the coefficient of x i.e. b : "); scanf("%f",&b); printf("Finally enter the constant term i.e. c : "); scanf("%f",&c); D = (b * b) - (4 * a * c); if (D < 0) printf("\n\nRoots are imaginary."); else if (D == 0) printf("\n\nRoots are equal and is %f",c/a); else { x1 = (-b + sqrt(D)) / (2 * a); x2 = (-b - sqrt(D)) / (2 * a); printf("\n\nFirst root is %f",x1); printf("\nSecond root is %f",x2); } printf("\n\nPress any key to exit..."); getch(); }