Loading

C Program to Convert decimal number to hexadecimal

C - Program to Convert decimal number to Hexadecimal

 


#include < stdio.h >
#include < conio.h > 
void main()
{
 int dec,rem[20],i,max,r;
 
 clrscr();
 printf("\n Enter a decimal number : ");
 scanf("%d",&dec);
 i = 0; 
 while ( dec != 0 )
 {
  r = dec % 16;
  dec = dec / 16;
  rem[i] = r;
  i++;
 } 
 i = i-1; 
 while ( i >=0)
 {
  if ( rem[i] < 10 )
  printf("%d",rem[i]);
  else
  printf("%c",55 + rem[i]);
  i--;
 } 
}



This entry was posted in . Bookmark the permalink.

Leave a reply