Advertisement
MeehoweCK

Untitled

May 25th, 2023
808
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. string odwroc_wyraz(string napis)
  6. {
  7.     string wynik = "";
  8.  
  9.     for (int i = napis.size() - 1; i >= 0; --i)
  10.         wynik += napis[i];
  11.  
  12.     return wynik;
  13. }
  14.  
  15. int main()
  16. {
  17.     int liczba;
  18.     cout << "Podaj liczbe calkowita:" << endl;
  19.     cin >> liczba;
  20.  
  21.     string liczba_16 = "";
  22.  
  23.     if (liczba == 0)
  24.         liczba_16 = "0";
  25.     else
  26.     {
  27.         int temp = liczba;
  28.         while (temp > 0)
  29.         {
  30.             int reszta = temp % 16;
  31.             if (reszta < 10)
  32.                 liczba_16 += ('0' + reszta);
  33.             else
  34.                 liczba_16 += ('A' + reszta - 10);
  35.             temp /= 16;
  36.         }
  37.  
  38.         liczba_16 = odwroc_wyraz(liczba_16);
  39.     }
  40.  
  41.     cout << liczba << " w systemie szesnastkowym to " << liczba_16 << endl;
  42.  
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement