#include <iostream>
#include <cmath>
// 计算二次方程根的函数
void calculateRoots(double a, double b, double c) {
double discriminant = b * b - 4 * a * c;
if (discriminant > 0) {
double root1 = (-b + sqrt(discriminant)) / (2 * a);
double root2 = (-b - sqrt(discriminant)) / (2 * a);
std::cout << "方程有两个实根:" << root1 << "和" << root2 << std::endl;
} else if (discriminant == 0) {
double root = -b / (2 * a);
std::cout << "方程有一个实根:" << root << std::endl;
} else {
double realPart = -b / (2 * a);
double imaginaryPart = sqrt(-discriminant) / (2 * a);
std::cout << "方程有两个复根:" << realPart << "+" << imaginaryPart << "i 和 "
<< realPart << "-" << imaginaryPart << "i" << std::endl;
}
}
int main() {
double a, b, c;
std::cout << "请输入a的值:";
std::cin >> a;
std::cout << "请输入b的值:";
std::cin >> b;
std::cout << "请输入c的值:";
std::cin >> c;
calculateRoots(a, b, c);
return 0;
}