Program to convert a number into HexaDecimal format
#include<stdio.h> #include<string.h> #include<stdlib.h> main() { int i=0,n,count=0,a[10]; char ch[10]; printf("enter a number\n"); scanf("%d",&n); while(n>0) { a[i]=(n%16); n=n/16; i++; count++; } for(i=count-1;i>=0;i--) { if(a[i]==10) ch[i]=a[i]+55; if(a[i]==11) ch[i]=a[i]+56; if(a[i]==12) ch[i]=a[i]+57; if(a[i]==13) ch[i]=a[i]+58; if(a[i]==14) ch[i]=a[i]+59; if(a[i]==15) ch[i]=a[i]+60; printf("%c",ch[i]); printf("\n"); } }OutPut:
enter a number 12 E