rikardoricz

17 IF Tomasz Świątek 3BTI/2

Nov 17th, 2020
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.47 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     int x;
  9.  
  10.     cout << "Podaj liczbe: " << endl;
  11.     cin >> x;
  12.  
  13.     // cout << "Wartosc bezwzgledna podanej liczby wynosi: " << abs(x);     alternatywne i szybsze rozwiazanie
  14.  
  15.     if (x<0)
  16.     {
  17.         cout << "Wartosc bezwzgledna podanej liczby wynosi: " << x*-1;
  18.     }
  19.     else
  20.     {
  21.         cout << "Wartosc bezwzgledna podanej liczby wynosi: " << x;
  22.     }
  23.  
  24.     return 0;
  25. }
  26.  
Advertisement
Add Comment
Please, Sign In to add comment