/*
* 功能:演示如何将十进制转换成16进制
*/
#include <stdio.h>
#include <stdlib.h>
void hex_covert(int x);
void hex_covert(int x)
{
char a;
int y;
if (x==0)
{
printf("0");
return ;
}
y = x%16;
if (y>=10)
a = (y - 10) + 'a';
else
a = y + '0';
x = x/16;
if (x != 0)
hex_covert(x);
printf("%c", a);
}
int main()
{
int x;
printf("\n\n===========Program Start==============\n");
printf("Please input a number to covert:");
scanf("%d", &x);
printf("Hex:%x\n\n", x);
printf("Now, let's use a function to covert\n");
printf("Hex:");
hex_covert(x);
printf("\n");
printf("=============Program End==============\n\n");
return 0;
}
如何将十进制转换成16进制
最新推荐文章于 2023-02-25 14:00:42 发布