Advertisement
BunchiePC

DEC->HEX

Jan 7th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.01 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <math.h>
  4.  
  5. using namespace std;
  6.  
  7. long long funkcja(long long a,int b);
  8.  
  9. int main()
  10. {
  11.     long long a;
  12.     cout << "Podaj dowolna liczbe w systemie dziesietnym: ";
  13.     cin >> a;
  14.     cout << "Liczba " << a << " w systemie heksadecymalnym to: ";
  15.     if(a==0) cout << 0;
  16.     else funkcja(a,16);
  17.  
  18.     return 0;
  19. }
  20.  
  21. long long funkcja(long long a,int b)
  22. {
  23.     int x=a%16;
  24.     if(a>0)
  25.     {
  26.         funkcja(a/16,16);
  27.         if(x>9)
  28.             switch(x)
  29.             {
  30.             case 10:
  31.                 cout<<"A";
  32.                 break;
  33.             case 11:
  34.                 cout<<"B";
  35.                 break;
  36.             case 12:
  37.                 cout<<"C";
  38.                 break;
  39.             case 13:
  40.                 cout<<"D";
  41.                 break;
  42.             case 14:
  43.                 cout<<"E";
  44.                 break;
  45.             case 15:
  46.                 cout<<"F";
  47.                 break;
  48.             }
  49.         else cout<<x;
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement