Write a program to determine the roots of quadratic equation



 Code:-

#include<stdio.h>
#include<math.h>
int main()
{
int a,b,c,D;
float x1,x2,m;
printf(“Enter the coffecient of the each term of the quadratic equationn”);
scanf(“%d%d%d”,&a,&b,&c);
D=(b*b)-(4*a*c);
if(D<0)
printf(“_Imaginary rootsn”);
else
{
m=sqrt(D);
x1=(-b+m)/(2*a);
x2=(-bm)/(2*a);
printf(“Roots of the equation are: %f and %f”,x1,x2);
}
return 0;
}

Output:-

Enter the coefficient of the each term of the quadratic equation
2 3 1
Roots of the equation are: 0.50000 1.000000

Recommended Post:-

         MCQs:-






Leave a Reply

Your email address will not be published.