基础练习 十进制转十六进制
进制转换忘了怎么转了....又用笔画了一下才弄明白,最后还得加一个0的判断,真烦
#include<bits/stdc++.h>
using namespace std;
char inttochar(int a)
{
if(a>=0&&a<=9) return a+'0';
else return a-10+'A';
}
int main()
{
int a;
cin>>a;
if(a==0)
{
cout<<0<<endl;
return 0;
}
string s="";
while(a)
{
s=inttochar(a%16)+s;
a=a/16;
}
cout<<s<<endl;
return 0;
}