Write a C Program to find the roots of a quadratic equation



int main()
float a, b, c, d, root1, root2;
printf("Enter the coefficients a, b and c : ");
scanf("%f %f %f", &a, &b, &c);
d = b*b - 4*a*c;
if (d==0){
printf("The roots of quardratic equation are__ %.2f", -b/(2*a));
else if (d>0){
root1=(-b + sqrt(d))/(2*a);
root2=(-b - sqrt(d))/(2*a);
printf("nRoot1 = %.2f",root1);
printf("nRoot2 = %.2f",root2);
float real, imag;
real = -b/(2*a);
imag = sqrt(-d)/(2*a);
printf("nRoot1 = %.2f+%.2fi", real, imag);
printf("nRoot2 = %.2f-%.2fi", real, imag);
return 0;
Leave a Reply

You cannot copy content of this page