Search
 
SCRIPT & CODE EXAMPLE
 

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);
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: c++ triangle 
Cpp :: how to clear screen in C++ console 
Cpp :: resize two dimensional vector c++ 
Cpp :: how to make crypto 
Cpp :: how to read a line from the console in c++ 
Cpp :: or in cpp 
Cpp :: how to print fixed places after decimal point in c++ 
Cpp :: how to loop a 2 dimensional vector in c++ starting from second element 
Cpp :: c++ round number up 
Cpp :: maximum value in map in c++ 
Cpp :: c++ user input 
Cpp :: print in c++ 
Cpp :: how to make for loop in c++ 
Cpp :: delete file cpp 
Cpp :: how to do (binary) operator overloading in c++ 
Cpp :: how to clear console c++ 
Cpp :: gfgdf 
Cpp :: how to iterate from second element in map c++ 
Cpp :: iterating in map/unordered map c++ 
Cpp :: copy a part of a vector in another in c++ 
Cpp :: random number generator c++ between 0 and 1 
Cpp :: c++ simple car game 
Cpp :: cpp initialize multidimensional vector 
Cpp :: string iterator in c++ 
Cpp :: c++ Program for Sum of the digits of a given number 
Cpp :: 1d array 
Cpp :: struct and pointer c++ 
Cpp :: vector length c++ 
Cpp :: int max c++ 
Cpp :: sqrt in c++ 
ADD CONTENT
Topic
Content
Source link
Name
8+7 =