#define _CRT_SECURE_NO_WARNINGS 1 //计算一元二次方程 #include <math.h> #include <stdio.h> int main() { float a, b, c, deter, x1, x2 = 0; while (scanf("%f %f %f", &a, &b, &c) != EOF) { if (a != 0) { deter = pow(b, 2) - 4 * a * c; if (deter == 0) { if (b != 0) { x1 = -b / (2 * a); printf("x1=x2=%.2f\n", x1); } else { printf("x1=x2=0.00\n"); } } else if (deter > 0) { x1 = ( - b + sqrt(deter)) / (2 * a); x2 = ( - b - sqrt(deter)) / (2 * a); printf("x1=%.2f;x2=%.2f\n", x2, x1); } else { x1 = -b / (2 * a);//实部 x2 = sqrt(-deter) / (2 * a);//虚部 printf("x1=%.2f-%.2fi;x2=%.2f+%.2fi\n", x1, x2, x1, x2); } } else { printf("Not quadratic equation\n"); } } return 0; }