0% found this document useful (0 votes)
19 views2 pages

Include

This C++ program takes in coefficients a, b, and c from the user and uses the quadratic formula to solve for the roots of a quadratic equation. It checks the discriminant to determine the number and type of solutions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views2 pages

Include

This C++ program takes in coefficients a, b, and c from the user and uses the quadratic formula to solve for the roots of a quadratic equation. It checks the discriminant to determine the number and type of solutions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <iostream>

#include <cmath>

using namespace std;

int main() {

float a, b, c, x1, x2,x, D;

cout << "Enter coefficients a, b and c: ";

cin >> a >> b >> c;

D = b*b - 4*a*c;

if (b == 0) {

cout << "imposible." << endl;

else if (c == 0) {

cout << "infinity ." << endl;

if (D > 0) {

x1 = (-b + sqrt(D)) / (2*a);

x2 = (-b - sqrt(D)) / (2*a);

cout << "x1 = " << x1 << endl;

cout << "x2 = " << x2 << endl;

else if (D == 0) {

x = -b/(2*a);

cout << "x =" << x << endl;

}
else if (D < 0) {

cout << "no solutions " << endl;

return 0;

You might also like