#include <stdio.h> #include <math.h> int main() { double a = 0.0; double b = 0.0; double c = 0.0; double x1 = 0.0; double x2 = 0.0; while (scanf("%lf %lf %lf", &a, &b, &c) != EOF) { if (0 == a)//判断a是否为0 { printf("Not quadratic equation\n"); } else { c = b * b - 4 * a * c;//由于后面的计算用不上原来的c了,所以给c赋上新的值△ if (0 == c)//有两个相等的实数根 { x1 = -b / (2 * a) + 0; printf("x1=x2=%.2lf\n", x1); } else if (c > 0)//有两个不相等的实数根 { x1 = (-b - sqrt(c)) / (2 * a); x2 = (-b + sqrt(c)) / (2 * a); printf("x1=%.2lf;x2=%.2lf\n", x1, x2); } else//解为复数 { x1 = (-b) / (2 * a); x2 = sqrt(-c) / (2 * a); printf("x1=%.2lf-%.2lfi;x2=%.2lf+%.2lfi\n", x1, x2, x1, x2); } } } return 0; }