Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

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);
}
 
PREVIOUS NEXT
Tagged: #quadratic #problem #solution
ADD COMMENT
Topic
Name
9+8 =