1
0
mirror of https://github.com/renbaoshuo/202401-programming-assignments.git synced 2024-12-16 15:44:39 +00:00
202401-programming-assignments/【额外练习】选择结构/7-29 选择-求解一元二次方程.c

32 lines
583 B
C
Raw Normal View History

2024-10-30 15:00:18 +00:00
#include <math.h>
#include <stdio.h>
int main() {
double a, b, c;
scanf("%lf%lf%lf", &a, &b, &c);
double delta = b * b - 4 * a * c;
if (delta > 0) {
double x1 = (-b - sqrt(delta)) / (a * 2);
double x2 = (-b + sqrt(delta)) / (a * 2);
if (x1 > x2) {
double temp = x1;
x1 = x2;
x2 = temp;
}
printf("%.2lf %.2lf\n", x1, x2);
} else if (delta == 0) {
double x1 = -b / (a * 2);
printf("%.2lf\n", x1);
} else {
printf("No solution\n");
}
return 0;
}