You are on page 1of 1

Find roots of quadratic equation.

#include <stdio.h>
#include<conio.h>
#include <math.h>
void main()
{
float a,b,c,x1,x2,disc;
printf("ent the value of coeffecient(a,b and c)\n");
scanf("%f%f%f",&a,&b,&c);
disc=b*b-4*a*c;
if (disc==0)
{
printf("roots are real and equal\n" );
x1=-b/(2*a);
x2=x1;
printf("1st root =%f\n",x1);
printf("2nd root =%f\n",x2);
}
else if (disc>0)
{
printf("roots are real and disntict\n");
x1=(-b+sqrt(disc))/(2*a);
x2=(-b-sqrt(disc))/(2*a);
printf("1st root =%f\n",x1);
printf("2nd root =%f\n",x2);
}
else
{
printf("imaginary roots\n");
x1=-b/(2*a);
x2=sqrt(fabs(disc))/(2*a);
printf("1st root =%f+i%f\n",x1,x2);
printf("2nd root =%f-i%f\n",x1,x2);
}
}

You might also like