数字转换问题
输入一个10进制的数将其转换为16进制的字符。
#include<iostream>
#include<vector>
using namespace std;
int main()
{
int a;
cin>>a;
int i,j;
vector <int> b;
if(a<16)
b.push_back(a);
while(a>=16)
{
b.push_back(a%16);
a=a/16;
if(a<16)
b.push_back(a);
}
for(j=b.size()-1;j>=0;j--)
{
switch(b[j])
{
case 0:
cout<<'0';break;
case 1:
cout<<'1';break;
case 2:
cout<<'2';break;
case 3:
cout<<'3';break;
case 4:
cout<<'4';break;
case 5:
cout<<'5';break;
case 6:
cout<<'6';break;
case 7:
cout<<'7';break;
case 8:
cout<<'8';break;
case 9:
cout<<'9';break;
case 10:
cout<<'A';break;
case 11:
cout<<'B';break;
case 12:
cout<<'C';break;
case 13:
cout<<'D';break;
case 14:
cout<<'E';break;
case 15:
cout<<'F';break;
}
}
return 0;
}