Website Summary Files Commits Branches @commit @diff @stats
path: root / Week04 / Exercise04.cpp
blob: a64f1f2744dc5e6df9871ed41810f04683642258 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
#include <cmath>

int main() {
    float a, b, c;
    std::cin >> a >> b >> c;

    float determinant = b * b - 4.0 * a * c;
    // Тези сравнения колко са коректни така?
    // Могат ли да се породят проблеми заради точност?
    if (determinant < 0.0) {
        std::cout << "No real roots";
    }
    else if (determinant == 0.0) {
        float x = -b / (2 * a);
        std::cout << x;
    }
    else {
        float x1 = (-b + sqrt(determinant)) / (2 * a);
        float x2 = (-b - sqrt(determinant)) / (2 * a);
        std::cout << x1 << ' ' << x2;
    }

    return 0;
}