#include <stdio.h>
#include <math.h>
int main()
{
double a, b, c, d, x1, x2;
char ch;
do
{
printf("请输入一元二次方程的三个系数:\n");
printf("请输入系数 a = \t");
scanf_s("%lf", &a);
printf("请输入系数 b = \t");
scanf_s("%lf", &b);
printf("请输入系数 c = \t");
scanf_s("%lf", &c);
if (a != 0)
{
d = b * b - 4 * a * c;//根的判别式
if (d > 0)
{
x1 = (-b + sqrt(d)) / (2 * a);
x2 = (-b - sqrt(d)) / (2 * a);
printf("有2个实数根:x1 = %.2lf x2 = %.2lf\n", x1, x2);
}
else if (d == 0)
{
x1 = (-b + sqrt(d)) / (2 * a);
printf("有2个相等实数根:x1=x2 = %.2lf\n", x1);
}
else
printf("无实数根\n");
}
else
{
x1 = (-c) / b;
printf("有一个实数根:x1=%.2lf\n", x1);
}
printf("是否继续吗:Y/N\n");
scanf_s("%c", &ch);
} while (ch == 'y' || ch == 'Y');
return 0;
}