#include <stdio.h>
#include <math.h>
int main()
{
double a,b,c,x1,x2,h,y,x;
scanf("%lf %lf %lf",&a,&b,&c);
if(a==0&&b==0)
{
if(c==0)
{
printf("Zero Equation\n");
}
else
{
printf("Not An Equation\n");
}
}
if(a==0&&b!=0)
{
x=-c/b;
printf("%.2lf\n",x);
}
if(a!=0)
{
h=b*b-4*a*c;
y=4*a*c-b*b;
if(h==0)
{
x1=x2;
x1=-b/2/a;
printf("%.2lf\n",x1);
}
if(h>0)
{
x1=(-b+sqrt(h))/2/a;
x2=(-b-sqrt(h))/2/a;
if(x1>x2)
{
printf("%.2lf\n",x1);
printf("%.2lf\n",x2);
}
else
{
printf("%.2lf\n",x2);
printf("%.2lf\n",x1);
}
}
if(h<0)
{
x1=-b/2/a;
x2=sqrt(y)/2/a;
if(x1!=0)
{
printf("%.2lf+%.2lfi\n",x1,x2);
printf("%.2lf-%.2lfi\n",x1,x2);
}
if(b==0)
{
x1=0;
printf("%.2lf+%.2lfi\n",x1,x2);
printf("%.2lf-%.2lfi\n",x1,x2);
}
}
}
return 0;
}
一元二次方程求解
最新推荐文章于 2024-09-25 09:50:19 发布