\* C Program using function to Convert Decimal to Hexadecimal *\
# include < stdio.h >
# include < conio.h >
# include < math.h >
int dec_hex( int )
int main()
{
int ch, dec_num, hex_num ;
long bin_num ;
printf( "\n Enter a decimal Number : ") ;
scanf( "%d",&dec_num ) ;
dec_hex( dec_num ) ;
return 0 ;
}
int dec_hex( int )
{
int i, n, a[50], rem ;
n = 1 ;
while( dec_num > 0 )
{
rem = dec_num % 16 ;
a[n] = rem ;
dec_num = dec_num/16 ;
n++ ;
}
printf(" Hexadecimal of Entred Decimal Number is :\n" ) ;
for( i = n-1; i>0; i-- )
{
if( a[i] > 9 )
{
switch( a[i] )
{
case 10 : printf("A ") ;
break ;
case 11 : printf("B ") ;
break ;
case 12 : printf("C ") ;
break ;
case 13 : printf("D ") ;
break ;
case 14 : printf("E ") ;
break ;
case 15 : printf("F ") ;
break ;
}
}
else
printf( " %d ",a[i] ) ;
}
}