求助 整数转换成十六进制字符串
设计一个函数itoh(n,s),能将一个无符号整数n转换成十六进制字符串
程序代码:
#include<stdio.h> #include<string.h> void itoh(int n,char *s) { char base[16] = {'0','1','2','3', '4','5','6','7', '8','9','A','B', 'C','D','E','F'}; int a = n; int i = 0; while(a != 0) { s[i++] = base[a%16]; a/=16; } } main() { int n = 43981; char a[80] = {0}; itoh(n,a); for(int i = strlen(a)-1;i>=0;i--) printf("%c",a[i]); printf("\n"); }