记录下来,因为我容易忘
#include<stdio.h> #include<math.h> int main() { double a, b, c; scanf("%lg%lg%lg", &a, &b, &c); printf("原方程为:%g*x*x + %g*x + %g = 0 ", a, b, c); if (a == 0) { if (b == 0) { if (c == 0) { printf(" x可以为任意值"); } else { printf(" x无解"); } } else { printf("该方程不是二次方程 x = %.2f ", -1.0 * c / b);//一元一次方程 } } else { int N = b * b - 4 * a * c; double X = -1.0 * b / 2 / a; if (N == 0) { printf("该方程有2个相等实根 x1 = %.2f, x2 = %.2f ", X, X); } else if (N > 0) { double Y = sqrt(N) / 2.0 / a; printf("该方程有2个不等实根 x1 = %.2f, x2 = %.2f ", X + Y, X - Y); } else { double Y = sqrt(-1.0 * N) / 2 / a; printf("该方程有2个共轭复根 x1 = %.2f+%.2fi, x2 = %.2f-%.2fi ", X, Y, X, Y); } } return 0; }
========================================Talk is cheap, show me the code=======================================