Advertisement
Guest User

5ta zad

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