1 #include<stdio.h> 2 #include<stdlib.h> 3 4 int main() 5 { 6 int ival; 7 8 char result[8] = ""; 9 char array[17] = "0123456789ABCDEF"; 10 int index = -1; 11 printf("input the value: "); 12 scanf_s("%d",&ival); 13 14 while(ival != 0) 15 { 16 index++; 17 result[index] = array[ival % 16]; 18 ival = ival / 16; 19 } 20 printf("Hex:"); 21 while(index >= 0) 22 { 23 printf("%c",result[index]); 24 index--; 25 } 26 system("pause"); 27 return 0; 28 }