Answers for "quadratic problem solution c++"

C++
1

quadratic problem solution c++

/* 
So basically this function returns pair of bool, which defines either problem
has any solution or not, and pair which contains two solutions that this problem
have(if it has any at all)
*/
pair<bool , pair<double, double>> qp(double a, double b, double c){
    double D = b*b - 4*a*c;
    if(D < 0){
        cout << "This problem can not be solved" << endl;;
        return make_pair(false, make_pair(-1, -1));
    }
    D = sqrt(D);
    double x1 = (D - b)/(2 * a); // first solution
    double x2 = -(D + b)/(2 * a); // second solution
    pair<double, double> answer = make_pair(x1, x2);
    return make_pair(true, answer);
}
Posted by: Guest on April-29-2022

Code answers related to "quadratic problem solution c++"

Browse Popular Code Answers by Language