方程根的问题(纠错)!
#include <stdio.h>float a,b,c,disc,x1,x2,p,q;
g(){
p=-b/(2*a);
q=sqrt(disc)/(2*a);
x1=p+q;
x2=p-q;
printf("%f,%f\n",x1,x2);
}
f(){ printf("%f,%f\n",x1,x2);
}
e(){ q=sqrt(fabs(disc))/(2*a);
printf("%f-%fi,%f+%fi\n",p,q,p,q);
}
main(){
disc=b*b-4*a*c;
scanf("%f %f %f",a,b,c);
if(disc>0) g();
else if(disc==0) f();
else e();
}
运行之后,无论a,b,c的值如何变化
输出结果始终为:0.000000,0.000000
NULL pointer assignment
本人无法找出错误之处,希望大家帮下忙!