Untitled
unknown
plain_text
2 years ago
605 B
9
Indexable
#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;
}
}
}
Editor is loading...