解题思路:利用求根公式
注意事项:导入数学库<math.h>
参考代码:
#include <stdio.h> #include <math.h> int main() { float a, b, c; scanf("%f %f %f", &a, &b, &c); float x1, x2; float mysqrt; if ((b * b - 4 * a * c) > 0) { mysqrt = sqrt(b * b - 4 * a * c); //b^2 - 4ac开根号的值 } x1 = ((-b) + mysqrt) / 2 * a; x2 = ((-b) - mysqrt) / 2 * a; if (x1 > x2) { printf("%.2f %.2f", x1, x2); } else { printf("%.2f %.2f", x2, x1); } return 0; }
0.0分
1 人评分