✔ 最佳答案
/* quadratic equation using Borland C-compiler, the include statement
should have been enclosed in angle brackets, shown in quotes because
yahooHK traps angle brackets \<>*/
#include "stdio"
#include "stdlib.h"
#include "math.h"
int main(int argc, char* argv[])
{
double array[3],a,b,c,x,x1,x2,D;
double eps=0.000000001; // tolerance
int i;
char li[200];
char ch[3]="abc";
printf("Solution of equation ax^2+bx+c=0\n");
for(i=0;i<3;i++)
{
printf("Enter %c:",ch[i]);
gets(li);
array[i]=atof(li);
}
a=array[0]; b=array[1]; c=array[2];
if(a==0&&b==0){
printf("The input parameters do not make an equation\n");
} else if(a==0){
x=-c/b;
printf("problem reduced to linear equation, x=%lf\n",x);
} else if(b*b<4*a*c){
printf("roots are complex, no real solution\n");
} else if(fabs(b*b-4*a*c less than eps){
printf("Two identical solutions are x=%f\n",-b/2/a);
} else {
D=sqrt(b*b-4*a*c);
x1=(-b+D)/2/a;
x2=(-b-D)/2/a;
printf("The solutions are x=%f and x=%f\n",x1,x2);
}
return 0;
}