Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Sep 21st, 2012  |  syntax: None  |  size: 0.80 KB  |  hits: 39  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.     #include <iostream>
  2.     using namespace std;
  3.     int main () {
  4.       int x, k;
  5.       cin >> x;
  6.  
  7.       if (x == 0) cout << 0 << endl;
  8.       else {
  9.           while ( x > 0) {
  10.               k = x % 16;
  11.               x = x / 16;
  12.               if ( k == 10 ) {
  13.                   cout << "A";
  14.               }
  15.               else if ( k == 11 ) {
  16.                    cout << "B";
  17.               }
  18.               else if ( k == 12 ) {
  19.                    cout << "C";
  20.               }
  21.               else if ( k == 13 ) {
  22.                    cout << "D";
  23.               }
  24.               else if ( k == 14 ) {
  25.                    cout << "E";
  26.               }
  27.               else if ( k == 15 ) {
  28.                    cout << "F";
  29.               }
  30.               else cout << k;
  31.           }
  32.        }
  33.     }