Write a program to solve a quadratic equation completely Gen
Write a program to solve a quadratic equation completely, Generally, such an equation, ax2+bx+c 0 always has two solutions, which can be found according to the following three cases. Define the discriminant A b2-4ac Case 1. Two different real valued solutions if A>0. x -bit b2-4ac a Case 2. Two indetical solutions if A 0. x -b2a Case 3. Two complex solutions if A
Solution
#include <stdio.h>
#include <math.h>
double determinant(int x,int y,int z);
int main() {
int a,b,c,det;
double r,s,t,u,v;
printf(\"enter cofficients a,b and c\");
scanf(\"%d%d%d\",&a,&b,&c);
det=determinant(a,b,c);
printf(\"%d\",det);
if(det>0)
{
r=sqrt((double)det);
s=(-b)+r;
t=(-b)-r;
u=s/(2*a);
v=t/(2*a);
printf(\"roots of x are %lf %lf \",u,v);
}
else if(det=0)
{
v=(-b)/(2*a);
printf(\"root of x is %lf\",v);
}
else if(det<0)
{
v=(-b)/(2*a);
r=sqrt((double)det);
s=r/(2*a);
printf(\"Complex roots of x are %lf +i %lf \",v,s);
}
return 0;
}
double determinant(int x,int y,int z)
{
int det,w,e;
w=y*y;
e=4*x*z;
det=w-e;
return det;
}
