一个C程序帮忙看看错在哪?

来源:百度知道 编辑:UC知道 时间:2024/07/02 03:16:31
#include "stdio.h"
#include "math.h"

int main()
{
float a,b,c,x1,x2;
printf ("a,b,c=?\n");
scanf ("%f%f%f",&a,&b,&c);
if (a==0)
printf ("The equation is not quadratic\n");
else
{
if (b*b-4*a*c==(1e-6))
printf ("The equation has two equal roots:%f",(-b/(2*a)));
if (b*b-4*a*c>0)
{
(float)x1=(-b+sqrt(b*b-4*a*c)/(2*a));
(float)x2=(-b-sqrt(b*b-4*a*c)/(2*a));
printf ("The equation has distinct real roots:%f and %f",x1,x2);
}
if (b*b-4*a*c<0)
{
printf ("The equation has complex roots:\n");
printf ("%f+%f%c\n",-b/(2*a),sqrt(4*a*c-b*b),'i');
printf ("%f-%f%c\n",-b/(2*a),sqrt(4*a*c-b*b),'i');
}
}

return 0;
}
求一元二次方程的解,a.b.c都要定义成float型

//---------------------------------------------------------------------------

#include "stdio.h"
#include "math.h"

int main(void)
{
float a,b,c,x1,x2;
printf ("a,b,c=?\n");
scanf ("%f%f%f",&a,&b,&c);
if (fabs(a)<=1e-6) /*注意这里*/
printf ("The equation is not quadratic\n");
else
{
if (fabs(b*b-4*a*c)<=(1e-6)) /*注意这里*/
printf ("The equation has two equal roots:%f",(-b/(2*a)));
else if (b*b-4*a*c>0) /*注意这里*/
{
x1=(-b+sqrt(b*b-4*a*c)/(2*a)); /*注意这里*/
x2=(-b-sqrt(b*b-4*a*c)/(2*a)); /*注意这里*/
printf ("The equation has distinct real roots:%f and %f",x1,x2);
}
else if (b*b-4*a*c<0) /*注意这里*/
{
printf ("The equation has complex roots:\n");
printf ("%f+%f%c\n",-b/(2*a),sqrt(4*a*c-b*b),'i');
printf ("%f-%f%c\n",-b