Advertisement
MeehoweCK

Untitled

Sep 30th, 2020
890
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. string odwroc_tekst(string tekst)
  6. {
  7.     string wynik = "";
  8.  
  9.     for(int i = tekst.size() - 1; i >= 0; --i)
  10.         wynik += tekst[i];
  11.     return wynik;
  12. }
  13.  
  14. int main ()
  15. {
  16.     int liczba;
  17.  
  18.     cout << "Wpisz liczbe: ";
  19.     cin >> liczba;
  20.  
  21.     if (liczba == 0)
  22.     {
  23.         cout << 0 << endl;
  24.         return 0;
  25.     }
  26.     string wynik = "";
  27.     while (liczba != 0)
  28.     {
  29.         if(liczba % 2 == 0)
  30.             wynik += '0';
  31.         else
  32.             wynik += '1';
  33.         liczba = liczba / 2;
  34.     }
  35.     cout << odwroc_tekst(wynik) << endl;
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement