#include <stdio.h>
#include <math.h>
main()
{
float a,b,c;
printf("Enter a,b,c:");
scanf("%f%f%f",&a,&b,&c);
func(a,b,c);
}
func(float a,float b,float c)
{
float d,temp1,temp2;
if (a==0)
{
if (b==0)
{
printf("Error!\n");
}
else
{
printf("Single root is %f.\n",-c/b);
}
}
else
{
d=b*b-4*a*c;
temp1=-b/(2*a);
temp2=sqrt(fabs((double)d))/(2*a);
if (d>=0)
{
printf("The roots are:%f and %f\n",temp1+temp2,temp1-temp2);
}
else
{
printf("The roots are:%f+%fi and %f-%fi\n",temp1,temp2,temp1,temp2);
}
}
}
[此贴子已经被作者于2007-9-3 19:20:17编辑过]