Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
605 B
1
Indexable
Never
#include <iostream>
using namespace std;
int main()
{
    double a, b, c, x1, x2, x;
    int d;
    cin>> a>> b>>c;
    d = b * b - 4 * a * c;
    if (d > 0) {
        d = 1;
    }
    if (d == 0) {
        d = 2;
    }
    switch (d) {
    case 1: {
        
        x1 = (b + sqrt(d))/2 * a;
        x2= (b - sqrt(d)) / 2 * a;
        cout <<"x1="<<x1 << endl;
        cout << "x2="<<x2;
        break;
    }
    case 2: {
       
        x = b / 2 * a;
        cout << "x="<< x;
        break;
    }
    default: {
        cout<< "NO";
        break;
    }

    }
}