笔者在编译器上得出结果如下图:
但在题库上通过了测试点,我很迷惑,请求指点。
#include <stdio.h>
#include <math.h>
int main()
{
printf("Please enter the coefficients a,b,c:");
float a,b,c,x1,x2;
scanf("%f,%f,%f",&a,&b,&c);
float p,i,q;
p=-b/(2*a);
i=b*b-4*a*c;
q=sqrt(fabs(i))/(2*a);
if(i==0){
printf("x1 = x2 = %.2f\n",p);
}else if(i>0){
printf("x1 = %.2f, x2 = %.2f\n",p+q,p-q);
}else if(i<0){
if(a!=0){
printf("x1 = %.2f+%.2fi, x2 = %.2f-%.2fi\n",p,q,p,q);
}else{
printf("It is not a quadratic equation!");
}
}
}