#include <iostream>
#include <cmath>
// Function to calculate the roots of a quadratic equation
void solveQuadraticEquation(double a, double b, double c) {
// Calculate the discriminant
double discriminant = b b - 4 a * c;
// Check the value of the discriminant
if (discriminant > 0) {
// Two real and distinct roots
double root1 = (-b + sqrt(discriminant)) / (2 * a);
double root2 = (-b - sqrt(discriminant)) / (2 * a);
std::cout << "Root 1: " << root1 << std::endl;
std::cout << "Root 2: " << root2 << std::endl;
} else if (discriminant == 0) {
// One real root (repeated)
double root = -b / (2 * a);
std::cout << "Root: " << root << std::endl;
} else {
// Complex roots
double realPart = -b / (2 * a);
double imaginaryPart = sqrt(-discriminant) / (2 * a);
std::cout << "Root 1: " << realPart << " + " << imaginaryPart << "i" << std::endl;
std::cout << "Root 2: " << realPart << " - " << imaginaryPart << "i" << std::endl;
}
}
int main() {
// Coefficients of the quadratic equation: ax^2 + bx + c = 0
double a, b, c;
// Input coefficients from the user
std::cout << "Enter coefficient a: ";
std::cin >> a;
std::cout << "Enter coefficient b: ";
std::cin >> b;
std::cout << "Enter coefficient c: ";
std::cin >> c;
// Call the function to solve the quadratic equation
solveQuadraticEquation(a, b, c);
return 0;
}