#include <stdio.h> #include <math.h> int main() { double a = 0.0; double b = 0.0; double c = 0.0; //多组输入 while (~scanf(" %lf%lf%lf", &a, &b, &c)) { if (0.0 == a) { //不是一元二次方程 printf("Not quadratic equation\n"); } else { //是一元二次方程 //一元二次方程判别式 double disc = b * b - 4 * a * c; if (0.0 == disc) { //两实根相等 printf("x1=x2=%.2lf\n", -b / (2 * a)); } else if (disc > 0.0) { //两实根不等 printf("x1=%.2lf;x2=%.2lf\n", (-b - sqrt(disc)) / (2 * a), (-b + sqrt(disc)) / (2 * a)); } else { //有两个虚根 printf("x1=%.2lf-%.2lfi;x2=%.2lf+%.2lfi\n", -b / (2 * a), sqrt(-disc) / (2 * a), -b / (2 * a), sqrt(-disc) / (2 * a)); } } } return 0; }