C Program to Find Roots of Quadratic Equation

#include <stdio.h>

#include<math.h>

#include<conio.h>

void main() {

    float a, b, c, d, r1, r2, rpart, ipart;

    clrscr();

    printf("Enter coefficients a, b and c\n ");

    scanf("%f %f %f", &a, &b, &c);

    d = b * b - 4 * a * c;

    if (d > 0)

 {

        r1 = (-b + sqrt(d)) / (2 * a);

        r2 = (-b - sqrt(d)) / (2 * a);

        printf("root1 = %f and root2 = %f", r1, r2);

    }

    else if (d == 0) 

   {

        r1 = r2 = -b / (2 * a);

        printf("root1 = root2 = %f;", r1);

    }

     else 

   {

        rpart = -b / (2 * a);

        ipart = sqrt(-d) / (2 * a);

        printf("root1 = %f + %fi and root2 = %f - %fi", rpart, ipart, rpart, ipart);

    }

    getch();