Quadratic Equation Solver

#include <stdio.h> #include <math.h> void main() { int a, b, c, d; float x1, x2, real, img; printf("Input the values of a, b & c: "); scanf("%d%d%d", &a, &b, &c); if (a == 0 && b == 0) { printf("Invalid inputs\n"); } else if (a == 0) { printf("Linear equation\n"); x1 = -c / (float)b; printf("Linear equation is: %f\n", x1); } else { d = b * b - 4 * a * c; if (d == 0) { printf("Both roots are equal.\n"); x1 = -b / (2.0 * a); x2 = x1; printf("First Root Root1= %f\n", x1); printf("Second Root Root2= %f\n", x2); } else if (d > 0) { printf("Both roots are real and different.\n"); x1 = (-b + sqrt(d)) / (2 * a); x2 = (-b - sqrt(d)) / (2 * a); printf("First Root Root1= %f\n", x1); printf("Second Root Root2= %f\n", x2); } else { printf("Roots are imaginary.\n"); real = -b / (2 * a); img = sqrt(fabs(d)) / (2 * a); printf("Root 1: %f + %fi\n", real, img); printf("Root 2: %f - %fi\n", real, img); } } }