Advertisement
rikardoricz

5 IF Tomasz Świątek 3BTI/2

Nov 17th, 2020
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #include <cmath>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int x,y;
  8.  
  9.     cout << "Podaj 2 liczby: " << endl;
  10.     cin >> x >> y;
  11.  
  12.     if (x<0)
  13.     {
  14.         x=x*-1;
  15.     }
  16.  
  17.     if (y<0)
  18.     {
  19.         y=y*-1;
  20.     }
  21.  
  22.     if (x>y)
  23.     {
  24.         cout << "Wieksza wartosc bezwzgledna ma pierwsza liczba: " << x;
  25.     }
  26.     else if (x<y)
  27.     {
  28.         cout << "Wieksza wartosc bezwzgledna ma druga liczba: " << y;
  29.     }
  30.     else
  31.     {
  32.         cout << "Wartosci bezwzgledne obu liczb sa takie same";
  33.     }
  34.  
  35.     /*
  36.     alternatywne rozwiazanie
  37.  
  38.     x = abs(x); //bezwzgledna x
  39.     y = abs(y); //bezwzgledna y
  40.  
  41.     if (x>y)
  42.     {
  43.         cout << "Wieksza wartosc bezwzgledna ma liczba x: " << x;
  44.     }
  45.     else
  46.     {
  47.         cout << "Wieksza wartosc bezwzgledna ma liczba y: " << y;
  48.     }
  49.     */
  50.     return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement