Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- string odwroc_tekst(string tekst)
- {
- string wynik = "";
- for(int i = tekst.size() - 1; i >= 0; --i)
- wynik += tekst[i];
- return wynik;
- }
- int main ()
- {
- int liczba;
- cout << "Wpisz liczbe: ";
- cin >> liczba;
- if (liczba == 0)
- {
- cout << 0 << endl;
- return 0;
- }
- string wynik = "";
- while (liczba != 0)
- {
- if(liczba % 2 == 0)
- wynik += '0';
- else
- wynik += '1';
- liczba = liczba / 2;
- }
- cout << odwroc_tekst(wynik) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement