language: C++ 4.7.2 (gcc-4.7.2)
date: 227 days 12 hours ago
link:
visibility: public
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
 
void convertToHex(int dec) {
    using std::cout;
    if (dec == 0)
        return;
    convertToHex(dec/16);
    int output = dec%16;
    if(output>9)
    {
        cout<<char(output+'A'-10);
    }
    else
    {
        cout<<output;
    }
    cout<<' ';
}
 
int main() {
    using std::cin;
    using std::cout;
    std::cout << "Enter a number: ";
    int n;
    std::cin >> n;
    convertToHex(n);
}