Advertisement
allia

квадратное уравнение

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