C program to convert decimal into hexadecimal.

 

01 #include<stdio.h>
02
03 int main()
04 {
05 long int decimalNumber,remainder,quotient;
06
07 int i=1,j,temp;
08
09 char hexadecimalNumber[100];
10
11 printf("Enter Decimal Number : ");
12 scanf("%ld",&decimalNumber);
13
14 quotient = decimalNumber;
15
16 while(quotient!=0)
17 {
18 temp = quotient % 16;
19
20 //integer into character
21 if( temp < 10)
22 temp =temp + 48;
23 else
24 temp = temp + 55;
25 hexadecimalNumber[i++]= temp;
26 quotient = quotient / 16;
27 }
28
29 printf("Hexadecimal value is : ");
30 for(j = i -1 ; j> 0; j--)
31 printf("%c",hexadecimalNumber[j]);
32
33 return 0;
34 }
 
 OUTPUT :

Enter Decimal Number : 451
HexaDecimal value is : 1C3

Related Post

Leave a Reply

Your email address will not be published. Required fields are marked *