Write a Program in C to find the roots of Quadratic Equation.
#include
#include
int main()
{
int a,b,c,det;
double root1,root2;
printf("Enter the value of
a, b and c from Quadratic
Equation\n");
scanf("%f \n %f \n %f \n"
,&a, &b, &c);
det=(b*b)-(4*a*c);
if(det<0)
{
printf("Root is imaginary.");
}
else if(det==0)
{
root1=(-b)/(2*a);
root2=root1;
}
else
{
root1=((-b)+pow(det,0.05))/(2*a);
root1=((-b)-pow(det,0.05))/(2*a);
}
printf("Root1=%.21f \n",root1);
printf("Root2=%.21f \n",root2);
return 0;
}
Enter the value of a, b and c
from Quadratic Equation
1
-2
1
Root1=1.00
Root2=1.00
Comments
Post a Comment