将10进制整数转换成16进制整数输出

题意:

       把十进制整数转换为十六进制,格式为0x开头,10~15由大写字母A~F表示。

Input

每行一个整数x,0<= x <= 2^31。

Output

每行输出对应的八位十六进制整数,包括前导0。

案例输出:

Sample Input

0
1023

Sample Output

0x00000000
0x000003FF

注意:

用cin>>输入时无需担心Output Limint Exceeded,而用scanf输入应该加上!=EOF。

代码如下:

 1 #include<iostream>
 2 #include<cstdio>
 3 using namespace std;
 4 int main()
 5 {
 6     int n;
 7     while(scanf("%d",&n)!=EOF)
 8     {
 9         printf("0x%08X
",n);
10     }
11     return 0;
12 }
原文地址:https://www.cnblogs.com/x512149882/p/4653724.html