#include
#include
#define EON 1e-6//为数字“1”
int main(void)
{
float a,b,c;
double mate1,mate2,t1,t2,t3;
printf("plaese input three numbers:");
scanf("%f,%f,%f",&a,&b,&c);
if(fabs(a)<=EON)
if(fabs(b)<=EON)
printf("方程无解");
else
printf("方程为一元一次方程,有一个根x=%.4f\n",-c/b);
else
{
mate1=b*b-4*a*c;
mate2=4*a*c-b*b;
t1=-b/(2*a);
t2=sqrt(fabs(mate1))/(2*a);//在判断之前防止根号里面数小于0
t3=sqrt(fabs(mate2))/(2*a);
if(mate1>EON)//相当于a>0
{
printf("方程有两个实根:\n");
printf("x1=%.4f,x2=%.4f",t1+t2,t1-t2);
}
else if(fabs(mate1)
{
printf("方程有一个实根:\n");
printf("x=%.4f",t1);
}
else
{
printf("方程有两个虚根:\n");
printf("x1=%.4f+%.4fi,x2=%.4f-%.4fi",t1,t3,t1,t3);
}
}
}
import math
EON=float(0.000001)
a=float(input('输入数字a:'))
b=float(input('输入数字b:'))
c=float(input('输入数字c:'))
if(math.fabs(a)<=EON):
if(math.fabs(b)<=EON):
print('方程无解')
else:
print("{0}{1}={2:.4f}".format("方程为一元一次方程,有一个根","x",-c/b),end='\n')
else:
mate1=b*b-4*a*c
mate2=4*a*c-b*b
t1=-b/(2*a)
t2=math.sqrt(math.fabs(mate1))/(2*a)
t3=math.sqrt(math.fabs(mate2))/(2*a)
if(mate1>EON):
print("{0}".format("方程有两个实根"),end='\n')
print("{0}={1:.4f},{2}={3:.4f}".format("x1",t1+t2,"x2",t1-t2))
elif math.fabs(mate1)
print('{0}'.format("方程有一个实根"),end='\n')
print("{0}={1:.4f}".format("x",t1))
else:
print('{0}'.format("方程有两个虚根"),end='\n')
print('{0}={1:.4f}+{2:.4f}{3},{4}={5:.4f}-{6:.4f}{7}'.format("x1",t1,t3,"i","x2",t1,t3,"i"))