#include #include using namespace std; int roots (double a, double b, double c, double & r1, double & r2) { //pre: a,b,c are the coefficients of x^2, x and 1 //post: returns the roots as reference parameters, // returns the number of roots as the function's return value double disc = b*b-4*a*c; if (disc>0) { r1 = (-b+sqrt(disc))/(2*a); r2 = (-b-sqrt(disc))/(2*a); return 2; } else if (disc == 0) { r1 = -b/(2*a); return 1; } else return 0; } int main() { double coefx2, coefx, coef1, root1, root2; int numroots; cout << "Enter the coefficients for x^2, x and 1: "; cin >> coefx2 >> coefx >> coef1; numroots = roots(coefx2, coefx, coef1, root1, root2); if (numroots == 0) cout << "No roots " << endl; else if (numroots == 1) cout << "There is only one root and it is " << root1 << endl; else cout << "There are two roots and they are " << root1 << " and " << root2 << endl; return 0; }