我什至无法从键盘上拿起b
和c
。输入a
值后它将停止,并始终给出结果,如0.0000。此代码有什么问题?
#include <iostream>
#include <math.h>
int main() {
float a,b,c,d;
float x1,x2;
printf("enter a,b,c\n");
scanf("%f %f %f", &a, &b, &c);
d = b*b - 4*a*c;
if (d<0) {
printf ("no real roots");
}
else
{
x1= (-b + sqrt (d)) / 2*a;
x2= (-b - sqrt (d)) / 2*a;
printf ("the roots are\n");
printf ("x1=%f x2=%f",x1,x2);
}
return 0;
}