题目描述
输入一个十进制正整数,将其转换成十五进制数。
十五进制数的数码有:0,1,2,3,4,5,6,7,8,9,A,B,C,D,E(A~E,分别表示10~14)
输入
1行,为一个十进制正整数(不超过100,000)。
输出
仅1行,为转换后的十五进制数。
注意:
10~14的十五进制数用大写字母A~E表示。
#include<iostream>
using namespace std;
int a[100001];
int main(){
int n;
cin>>n;
int n1=n;
int i=0;
while(n1){
a[i]=n1%15;
n1/=15;
i++;
}
for(int j=i-1;j>=0;j--){
if(a[j]<10){
cout<<a[j];
}else if(a[j]==10){
cout<<'A';
}else if(a[j]==11){
cout<<'B';
}else if(a[j]==12){
cout<<'C';
}else if(a[j]==13){
cout<<'D';
}else if(a[j]==14){
cout<<'E';
}else if(a[j]==15){
cout<<'F';
}
}
}