3. Write a program to determine the roots of quadratic equation

 SOURCE CODE:


#include <stdio.h>
#include<math.h>

int main()
{   float a,b,c,D,x,y;
    printf("enter the coefficients of quadratic equation\n");
    scanf("%f %f %f",&a,&b,&c);
    D=(b*b-4*a*c);
    x=(-b+sqrt(D))/(2*a);
    y=(-b-sqrt(D))/(2*a);
    printf("discriminant is %f\n",D);
    if(D==0){
        printf("roots are real and equal: %f, %f",x,y);
    }
    else if(D>0){
        printf("roots are real: %f, %f",x,y);
    }
    else{  
           printf("roots are imaginary: %f+%fi , %f-%fi",(-b/2*a),sqrt(-D)/(2*a),(-b/2*a),sqrt(-D)/(2*a));
    }

    return 0;
}



Comments