#include <stdio.h>
#include <math.h>
int main() {
double a, b, c, discriminant, root1, root2;
printf("请输入一元二次方程的系数 a, b 和 c: ");
scanf("%lf %lf %lf", &a, &b, &c);
discriminant = b * b - 4 * a * c;
if (discriminant > 0) {
root1 = (-b + sqrt(discriminant)) / (2 * a);
root2 = (-b - sqrt(discriminant)) / (2 * a);
printf("方程的两个根是 %.2lf 和 %.2lf\n", root1, root2);
} else if (discriminant == 0) {
root1 = root2 = -b / (2 * a);
printf("方程的两个根是 %.2lf 和 %.2lf\n", root1, root2);
} else {
printf("方程无实数根。\n");
}
return 0;
}
#include <math.h>
int main() {
double a, b, c, discriminant, root1, root2;
printf("请输入一元二次方程的系数 a, b 和 c: ");
scanf("%lf %lf %lf", &a, &b, &c);
discriminant = b * b - 4 * a * c;
if (discriminant > 0) {
root1 = (-b + sqrt(discriminant)) / (2 * a);
root2 = (-b - sqrt(discriminant)) / (2 * a);
printf("方程的两个根是 %.2lf 和 %.2lf\n", root1, root2);
} else if (discriminant == 0) {
root1 = root2 = -b / (2 * a);
printf("方程的两个根是 %.2lf 和 %.2lf\n", root1, root2);
} else {
printf("方程无实数根。\n");
}
return 0;
}