Approximate idea:
Enter any decimal digit first to determine the number of digits;
uses an array of shapes to store hexadecimal digits; a[0] represents the number of digits in hexadecimal digits;
#include <stdio.h>#include<stdlib.h>#defineMAXSIZE 10int* Ahex (intDec) { intn=1; intm= -; int*A; A= (int*)malloc(sizeof(int) *maxsize+1); while(Dec >=m) {m= m* -; N++; }//printf ("number of positions:%d\n", N); *a =N; while(n>0) { * (a+n) = dec/(m/ -); Dec= dec-* (a+n) * (m/ -); N--; M= m/ -; } returnA;}voidPrint_hex (int*p) { intn = *p; printf ("hex:0x"); while(n>0) { Switch(* (p+N)) { Case Ten:p rintf ("A"); Break; Case One:p rintf ("B"); Break; Case A:p rintf ("C"); Break; Case -:p rintf ("D"); Break; Case -:p rintf ("E"); Break; Case the:p rintf ("F"); Break; default: printf ("%d", * (P+n)); Break; } N--; } printf ("\ n");}intMain () {intRec=0; int*p; while(1) {printf ("Please enter a decimal number:"); scanf ("%d",&rec); P=Ahex (REC); Print_hex (P); } return 0;}
Final effect:
"C language" any decimal digit to hex