Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- int main() {
- double a;
- double b;
- double c;
- double x1, x2, D;
- cin >> a >> b >> c;
- D = (b * b - 4 * a * c);
- // if 1 element == 0
- // a == 0
- if (a == 0 && (b != 0 && c!=0))
- {
- c = c*-1;
- cout << c/b;
- return 0;
- }
- // b == 0
- else if (b == 0 && (a != 0 && c!=0))
- {
- c = c*-1;
- if (c/a > 0){
- cout << pow(c/a,0.5);
- }
- return 0;
- }
- // if 2 elements == 0
- // a,b == 0
- else if (a == 0 && b ==0)
- {
- return 0;
- }
- // b,c == 0
- else if (b == 0 && c ==0)
- {
- return 0;
- }
- // a,c == 0
- else if (a == 0 && c ==0)
- {
- return 0;
- }
- else {
- if (D >= 0) //Если дискриминант больше или равен 0
- {
- D = pow(D, 0.5);
- a = 2 * a;
- x1 = (-1 * b + D) / a;
- x2 = (-1 * b - D) / a;
- if (x1==x2){
- cout << x2 << endl;
- }
- else{
- cout << x1 << " " << x2 << endl;
- }
- } else {
- cout << endl;
- }
- }
- return 0;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement