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 liczba_16 = "";
- if (liczba == 0)
- liczba_16 = "0";
- else
- {
- int temp = liczba;
- while (temp > 0)
- {
- int reszta = temp % 16;
- if (reszta < 10)
- liczba_16 += ('0' + reszta);
- else
- liczba_16 += ('A' + reszta - 10);
- temp /= 16;
- }
- liczba_16 = odwroc_wyraz(liczba_16);
- }
- cout << liczba << " w systemie szesnastkowym to " << liczba_16 << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement