This is a C program to Convert Decimal to Hexadecimal.
This program takes a decimal number as input and converts to hexadecimal.
1. Take a decimal number as input.
2. Divide the input number by 16. Store the remainder in the array.
3. Do step 2 with the quotient obtained until quotient becomes zero.
4. Print the array in the reversed fashion to get hexadecimal number.
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; else hexadecimalnum[j++] = 55 + remainder; quotient = quotient / 16; } // display integer into character for (i = j; i >= 0; i–)
Runtime Test Cases
Enter decimal number: 12
Equivalent hexadecimal value of 12 : C