csansoon

P2.06 P60816 Reversed number in hexadecimal

Sep 21st, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.33 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5.     int n;
  6.     const int BASE = 16;
  7.     cin >> n;
  8.     if( n != 0 ) {
  9.         while (n > 0) {
  10.             if( n%BASE < 10) cout << n%BASE;
  11.             else cout << char('A' + n%BASE - 10);
  12.             n = n/BASE;
  13.         }
  14.     }else cout << 0;
  15.     cout << endl;
  16. }
Add Comment
Please, Sign In to add comment