// Determines the roots of a quadratic equation - math function demo // mikhail nesterenko // 10/1/99 #include #include using std::cin; using std::cout; using std::endl; int main() { cout << "Enter coefficients for quadratic equation: "; // entering the coefficients double a, b, c; cin >> a >> b >> c; // calculate determinant const double determinant = sqrt(pow(b,2) - 4*a*c); if ((a != 0) && (determinant > 0)) { const double root1 = (-b + determinant) / (2*a); // first root const double root2 = (-b - determinant) / (2*a); // second root // output results cout << "The roots of " << a << "x**2 + " << b << "x + " << c << " are " << root1 << " and " << root2 << endl; }else cout << "Equation does not have two real roots\n"; }