14 C program to Convert Decimal to Hexadecimal
Posted by Superadmin on December 22 2015 03:16:24
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, remainder, quotient;
int i = 1, j, temp;
char hexadecimalnum[100];
printf("Enter decimal number: ");
scanf("%ld", &decimalnum);
quotient = decimalnum;
while (quotient != 0)
{
temp = quotient % 16;
// To convert integer into character
if (temp 0; j--)
printf("%c", hexadecimalnum[j]);
return 0;
}
Output:
$ cc pgm1.c
$ a.out
Enter decimal number: 12
Equivalent hexadecimal value of 12 : C