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`

`*/`

`#include <stdio.h>`

int main()

`{`

long decimalnum, quotient, remainder;

int i, j = 0;

char hexadecimalnum[100];

printf("Enter decimal number: ");

scanf("%ld", &decimalnum);

quotient = decimalnum;

while (quotient != 0)

`{`

remainder = quotient % 16;

if (remainder < 10)

hexadecimalnum[j++] = 48 + remainder;

`else`

hexadecimalnum[j++] = 55 + remainder;

quotient = quotient / 16;

`}`

`// display integer into character`

for (i = j; i >= 0; i--)

printf("%c", hexadecimalnum[i]);

return 0;

`}`

Output: $ cc pgm1.c $ a.out Enter decimal number: 12 Equivalent hexadecimal value of 12 : C

**Sanfoundry Global Education & Learning Series – 1000 C Programs.**

Here’s the list of Best Reference Books in C Programming, Data-Structures and Algorithms

If you wish to look at other example programs on Simple C Programs, go to Simple C Programs. If you wish to look at programming examples on all topics, go to C Programming Examples.