高手,我这儿有一问题:解一元二次方程a x2+ b x + c = 0的根,a、b、c由键盘输入。编译能通过,但输出结果不对,望不啬赐教,我先谢过浏览此贴的仁士。我编的程序如下:
#include "stdio.h"
main()
{
float a,b,c,x1,x2,rootsizeup;
printf("This is a program about evaluate ax2+bx+c=0.\nPlease input a,b,c.\n");/ *打印提示语 * /
scanf("%f %f %f",&a,&b,&c);/ *输入a,b,c * /
rootsizeup=b*b-4*a*c;/*判别式rootsizeup=b的平方+4ac * /
if (rootsizeup>0)/ *如果判别式>0,方程有两实数根 * /
{
printf ("This equation have two diffrent root:\n");
x1=-b+sqrt(rootsizeup)/(2*a);/ *x1= (-b+√(b2
x2=-b-sqrt(rootsizeup)/(2*a);
printf ("x1=%f\nx2=%f\n",x1,x2);
}
else if (rootsizeup==0)/ *如果判别式=0,方程有一实数根 * /
{
printf("This equation have one root:\n");
x1=-b+sqrt (rootsizeup)/(2*a);
printf("x=%f\n",x1);
}
else if (rootsizeup<0) / *如果判别式<0,方程没有实数根 * /
printf("This equation have no float root.\n");
}