C Program to convert decimal to hexadecimal number
Program
#include<stdio.h>
void decimal_hexa(int num)
{
int rem;
int base = 16;
long int h = 0;
if (num != 0)
{
rem = num % base;
decimal_hexa(num/base);
if(rem >= 10)
{
printf("%c",rem+55);
}
else
{
printf("%d",rem);
}
}
}
int main()
{
int num;
printf("Enter a number: ");
scanf("%d", &num);
printf("Hexadecimal equivalent is : ");
decimal_hexa(num);
return 0;
}
Output
$ gcc convert-decimal-to-hexa.c
$ ./a.out
Enter a number: 121
Hexadecimal equivalent is : 79