求一元二次方程根
这是我写的一个求一元二次根的程序,但当b*b-4ac<0时的根求不出来,请帮我看看错在哪里?谢谢!#include "stdio.h"
#include "math.h"
double x1,x2,disc,m,n;
greater_zero(double a,double b)
{
x1=((-b+sqrt(disc))/(2*a));
x2=((-b-sqrt(disc))/(2*a));
}
equa_zero(double a,double b)
{
x1=-b/(2*a);
}
smaller_zero(double a,double b)
{
double m,n;
m=-b/(2*a);
n=sqrt(disc)/(2*a);
}
main()
{double a,b,c;
scanf("%lf%lf%lf",&a,&b,&c);
printf("方程为:%.3lfx*x+%.3lfx+%.3lf=0\n",a,b,c);
disc=b*b-4*a*c;
printf("方程的解是:\n");
if(disc>0)
{
greater_zero(a,b);
printf("x1=%lf\nx2=%lf",x1,x2);
}
else if(disc==0)
{
equa_zero(a,b);
printf("x1=x2=%lf",x1);
}
else
{
smaller_zero(a,b);
printf("x1=%lf+%lfi\nx2=%lf-%lfi\n",m,n,m,n);
printf("%lf",m);
}
}