代码:
#include <stdio.h> #include <stdlib.h> /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int main(int argc, char *argv[]) { int n; int count=0; int temp; int i; char num[10000]; scanf("%d",&n); do{ temp = n%16; if(temp>9){ switch(temp){ case 10: num[count]='A'; break; case 11: num[count]='B'; break; case 12: num[count]='C'; break; case 13: num[count]='D'; break; case 14: num[count]='E'; break; case 15: num[count]='F'; break; } count++; }else{ num[count]=n%16+'0'; count++; } n = n/16; }while(n!=0); for(i=count-1;i>=0;i--){ printf("%c",num[i]); } return 0; }
运行结果: