C program to convert decimal number to hexadecimal number.

source code


#include<stdio.h>
 int main()
{
    long int decimalNumber,remainder,quotient;
    int i=1,j,temp;
    char hexadecimalNumber[100];
    printf("Enter any decimal number: ");
    scanf("%ld",&decimalNumber);
    quotient = decimalNumber;
    while(quotient!=0)
{
         temp = quotient % 16;
          //To convert integer into character
      if( temp < 10)
           temp =temp + 48;
      else
         temp = temp + 55;

      hexadecimalNumber[i++]= temp;
           quotient = quotient / 16;
  }
  printf("Equivalent hexadecimal value of decimal number %d:", decimal Number);    for(j = i -1 ;j> 0;j--)
printf("%c",hexadecimalNumber[j]);
 getch();
 return 0;
}

Comments

Popular posts from this blog

8086 STRING MANIPULATION –FIND AND REPLACE A WORD

Animated Circles In C++

C program to find out the sum of series 1 + 2 + …. + n.