#include <iostream>
using namespace std;
int ToHex(int n, char *src)
{
int imod = 0;
if(NULL == src)
return -1;
if(n < 0)
{
n=-n;
*src = '-';
++src;
}
while(n != 0)
{
imod = n % 16;
n = n/16;
if(imod > 9)
*src = imod - 10 + 'A';
else
*src = imod + '0';
++ src;
}
return 1;
}
int main()
{
int n;
char *hexStr = new char[20];
memset(hexStr,0,20);
cout<<"please input a Dec number:";
cin>>n;
int iflg = ToHex(n, hexStr);
if( iflg == -1 )
exit(1);
cout << hexStr << endl;
delete hexStr;
return 0;
}