程序没有问题的,是输入数据的问题,原因如下:
x的平方+1=0是没有解啊
b的平方-4ac=-4都小于0了
#include "stdio.h"
#include "math.h"
int main() {
double a, b, c, disc, x1, x2, p, q;
scanf("%lf%lf%lf", &a, &b, &c);
disc = b * b - 4 * a * c;
p = -1 * b / (2.0 * a);
q = sqrt(disc) / (2.0 * a);
x1 = p + q;
x2 = p - q;
printf("x1=%7.2lf,x2=%7.2lf\n", x1, x2);
return 0;
}