求ax2+bx+c=0的根,三种情况的代码,我写了一些有错误求解答
#include<stdio.h>#include<math.h>
int main()
{
double a,x1,x2,p,q,disc,b,c; //disc是判别式
printf("please input a,b,c=");
scanf("%lf%lf%lf",&a,&b,&c); //double型要用%lf
disc = b*b-4*a*c;
if(disc<0)
printf("no real roots");
if(disc>0)
{ p = -b/(2.0*a);
q = sprt(disc)/(2.0*a);
x1 = p + q;
x2 = p - q;
printf("real roots:\nxl=%7.2f\nx2=%7.2f\n",x1,x2);
}
else
printf("the same roots:\nx1=%7.2f\nx2=%7.2f\n",x1,x2);
return 0;
}
C:\Users\Administrator\AppData\Local\Temp\ccMqBdsj.o t4.c:(.text+0xce): undefined reference to `sprt'
C:\t1\collect2.exe [Error] ld returned 1 exit status