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