This C Program Converts the given Decimal to Hexadecimal. Decimal is a term that describes the base-10 number system commonly used by lay people in the developed world. Hexadecimal is base 16 arithmetic where each digit is a value from 0 to 15, rather than the 0-9 of base 10.
Here is source code of the C program to Convert Decimal to Hexadecimal. The C program is successfully compiled and run on a Linux system. The program output is also shown below.
* C program to Convert Decimal to Hexadecimal
long decimalnum, quotient, remainder;
int i, j = 0;
printf("Enter decimal number: ");
quotient = decimalnum;
while (quotient != 0)
remainder = quotient % 16;
if (remainder < 10)
hexadecimalnum[j++] = 48 + remainder;
hexadecimalnum[j++] = 55 + remainder;
quotient = quotient / 16;
// display integer into character
for (i = j; i >= 0; i--)
Output: $ cc pgm1.c $ a.out Enter decimal number: 12 Equivalent hexadecimal value of 12 : C
Sanfoundry Global Education & Learning Series – 1000 C Programs.