C语言为什么输出一直是-0.00

#include <stdio.h>
#include <math.h>
int main()
{
float a,b,c,x1,x2;
scanf ("a=%f",&a);
scanf ("b=%f",&b);
scanf ("c=%f",&c);
x1=(-b+sqrt((b*b)-(4*a*c)))/(2*a);
x2=(-b-sqrt((b*b)-(4*a*c)))/(2*a);
printf ("x1=%.2f\n",x1);
printf ("x2=%.2f\n",x2);
return 0
}

#include <stdio.h
#include <math.h>

int main() { 
double a,b,c,x1,x2,delta; 
scanf ("%lf%lf%lf",&a,&b,&c); 
delta = b*b-4*a*c;
if(delta >= 0.0) {
x1 = (-b + sqrt(delta))/(2*a); 
x2 = (-b - sqrt(delta))/(2*a); 
printf ("x1 = %.2lf\n",x1);
printf ("x2 = %.2lf\n",x2);
}
else printf("没有实数根。\n");
return 0;
}

温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网