求元二次方程的根
下面求一元二次方程的根的程序错在哪里呢?能够运行,但结果是错误的。#include "math.h"
float x1,x2,d,p,q;
getzero(a,b)
float a,b;
{x1=(-b+sqrt(d))/(2*a);x2=(-b-sqrt(d))/(2*a);}
eqzero(a,b)
float a,b;
{x1=x2=-b/(2*a);}
ltzero(a,b)
float a,b;
{p=-b/(2*a);q=sqrt(-d)/(2*a);}
main ()
{ float a,b,c,d;
printf ("input a,b,c:");
scanf ("%f%f%f",&a,&b,&c);
d=b*b-4*a*c;
printf ("方程的解为:");
if (d>0)
{getzero (a,b);printf ("x1=%5.2f\t x2=%5.2f\n",x1,x2);}
else if (d==0)
{eqzero(a,b);printf ("x1=x2=%5.2f\n",x1);}
else
{ltzero(a,b);printf ("x1=%5.2f+%5.2fi\t x2=%5.2f-%5.2fi\n",p,q,p,q);}
getch();
}