Advertisement
Sonya_Rosha

Untitled

Feb 18th, 2020
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8.     double a, b, c;
  9.     cin >> a >> b >> c;
  10.  
  11.     if (a == 0 && b != 0) {
  12.         if (c != 0) {
  13.             auto x = (-c) / b;
  14.             cout << x;
  15.         }
  16.         else
  17.             cout << 0;
  18.     }
  19.     else if (a != 0 && b == 0) {
  20.         if (c < 0) {
  21.             auto x = sqrt((-c) / a);
  22.             cout << -x << " " << x;
  23.         }
  24.         else if (c = 0)
  25.             cout << 0;
  26.         else
  27.             cout << "";
  28.     }
  29.     else if (a == 0 && b == 0) {
  30.         cout << "";
  31.     }
  32.     else {
  33.         auto D = b * b - 4 * a * c;
  34.  
  35.         if (D > 0) {
  36.             auto first_x = (-b - sqrt(D)) / (2 * a);
  37.             auto second_x = (-b + sqrt(D)) / (2 * a);
  38.             cout << first_x << " " << second_x;
  39.         }
  40.         else if (D == 0) {
  41.             auto x = -b / (2 * a);
  42.             cout << x;
  43.         }
  44.         else
  45.             cout << "";
  46.     }
  47.  
  48.     system("pause");
  49.     return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement