#54744: CPP解法(我參考C大神有放在github)


5b3g0036@stust.edu.tw (陳相樺)


‵‵‵

#include <iostream>
#include <cmath>


using namespace std;

// void a005() {
//     int input, a, b, c, d;

//     cin >> input;

//     for(int i = 0; i < input; i++) {
//         cin >> a >> b >> c >> d;
//         if(b - a == c - b && c - b == d - c) {
//             cout << a << " " << b << " " << c << " " << d << " " << d + (b - a) <<  endl;
//         }
//         else {
//             cout << a << " " << b << " " << c << " " << d << " " << d * (b / a) <<  endl;
//         }
//     }
// }

void a006() {
    int a, b, c, total;
    float x1, x2;

    cin >> a >> b >> c;

    total = (b*b) - (4 * a * c);
    x1 = (-b + sqrt((b * b) - (4 * a * c))) / (2 * a);
    x2 = (-b - sqrt((b * b) - (4 * a * c))) / (2 * a);

    if(total < 0) {
        cout << "No real root" << endl;
    } else if(total > 0) {
        cout << "Two different roots x1=" << x1 << " , x2=" << x2 << endl;
    } else {
        cout << "Two same roots x=" << x1 << endl;
    }
}

int main() {
//    a005();
    a006();
    return 0;
}

‵‵‵