发布时间:2026-07-21阅读(1)

题目
时间限制: 1 Sec 内存限制: 128 MB
题目描述
输入一个十进制数,输出对应的十六进制数。
十六进制数字从小到大为0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F

输入
一行,一个整数N,0<N<10000
输出
一行,一个十六进制数。
样例输入 Copy
123
样例输出 Copy
7B

答案在下方
答案:
#include<bits/stdc .h>using namespace std;void IntZh0x(int n){ int s=n; if(n/16!=0) IntZh0x(n/16); if(s>9) { if(s==15) cout<<"F"; else if(s==14) cout<<"E"; else if(s==13) cout<<"D"; else if(s==12) cout<<"C"; else if(s==11) cout<<"B"; else if(s==10) cout<<"A"; } else cout<<s;}int main(){ int n; cin>>n; IntZh0x(n); return 0;}
Copyright © 2024 有趣生活 All Rights Reserve吉ICP备19000289号-5 TXT地图HTML地图XML地图