C++ Program to Find Roots of Quadratic Equation
Write C++ Program to Find Roots of Quadratic Equation
// CPP Program to Find Roots of Quadratic Equation #include <iostream> #include <math.h> using namespace std; int main() { float a, b, c, delta, root1, root2; cout << "Enter Coefficient a :--> "; cin >> a; cout << "Enter Coefficient b :--> "; cin >> b; cout << "Enter Coefficient c :--> "; cin >> c; delta = b * b - 4 * a * c; root1 = (-b + sqrt(delta)) / (2 * a); root2 = (-b - sqrt(delta)) / (2 * a); cout << "\nRoot 1 = " << root1; cout << "\nRoot 2 = " << root2; return 0; }
Output:
Enter Coefficient a :--> 4
Enter Coefficient b :--> 8
Enter Coefficient c :--> 2
Root 1 = -0.29
Root 2 = -1.71