Advertisement
Guest User

Untitled

a guest
Apr 9th, 2020
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.26 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. #include <cmath>
  4. using namespace std;
  5.  
  6. int main() {
  7.     double a;
  8.     double b;
  9.     double c;
  10.     double x1, x2, D;
  11.     cin >> a >> b >> c;
  12.     D = (b * b - 4 * a * c);
  13.     // if 1 element == 0
  14.     // a == 0
  15.     if (a == 0 && (b != 0 && c!=0))
  16.     {
  17.         c = c*-1;
  18.         cout << c/b;
  19.         return 0;
  20.     }
  21.     // b == 0
  22.     else if  (b == 0 && (a != 0 && c!=0))
  23.     {
  24.         c = c*-1;
  25.         if (c/a > 0){
  26.             cout << pow(c/a,0.5);
  27.         }
  28.         return 0;
  29.     }
  30.     // if 2 elements == 0
  31.     // a,b == 0
  32.     else if  (a == 0 && b ==0)
  33.     {
  34.         return 0;
  35.     }
  36.     // b,c == 0
  37.     else if  (b == 0 && c ==0)
  38.     {
  39.         return 0;
  40.     }
  41.     // a,c == 0
  42.     else if  (a == 0 && c ==0)
  43.     {
  44.         return 0;
  45.     }
  46.  
  47.     else {
  48.         if (D >= 0) //Если дискриминант больше или равен 0
  49.         {
  50.             D = pow(D, 0.5);
  51.             a = 2 * a;
  52.             x1 = (-1 * b + D) / a;
  53.             x2 = (-1 * b - D) / a;
  54.             if (x1==x2){
  55.                 cout  << x2 << endl;
  56.             }
  57.             else{
  58.                 cout << x1 << " " << x2 << endl;
  59.             }
  60.         } else {
  61.             cout << endl;
  62.         }
  63.     }
  64.  
  65.     return 0;
  66. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement