# c program to convert decimal number to hexadecimal number

list of c programs below: c program to convert decimal number to hexadecimal number using functions, c program to convert decimal number to hexadecimal number without functions

Hexadecimal number is a number represented using 16 symbols which are 0 -9 numbers and A – F alphabets. Procedure to convert decimal number to hexadecimal number is: Divide the decimal  number with 16 at each step and take remainders

Here for remainders 0 – 9 numbers are used and then to represent 10 to 15 numbers we use alphabets A, B, C, D, E, F .

eg  To convert decimal number 10 to hexadecimal

16  | 10
| 0 – A

Now combine all remainders serially from down to up  i.e  A . This is hexadecimal number of  10 (decimal )

Program Logic: Enter decimal number n, divide n by 16 ( since hexadecimal ) and save remainder in array and quotient in n repeat until n is greater than zero

## Write a C program to convert decimal number to hexadecimal number using functions

Write a C Program to convert decimal number to hexadecimal using functions

#include <stdio.h>
void main()
{
int num;
printf(“\n OUTPUT: c program for converting decimal number to hexadecimal number \n Enter decimal number: “);
scanf(“%d”,&num);
printf(“\n Hexadecimal number of binary number %d is: num”);
}

{
while (n>0)
{
int i=0,b;
b[i]=n%16;
n=n/16;
i++;
}
while(i>0)
{
if (b[i]<10)
{
printf(b[i]);
}
else
{
switch(b[i])
{
case 10:
printf(“A”);
break;
case 11:
printf(“B”);
break;
case 12:
printf(“C”);
break;
case 13:
printf(“D”);
break;
case 14:
printf(“E”);
break;
case 15:
printf(“F”);
break;
}
//close switch
}
//close else
i–;
}
//close while
}
//close main
}
//close function

## Write a C program to convert decimal number to hexadecimal number without functions

Write a c program to convert decimal number to hexadecimal number without functions

#include <stdio.h>
void main()
{
int i=0,n,b;
printf(“\n OUTPUT: c program for converting decimal number to hexadecimal number \n Enter decimal number: “);
scanf(“%d”,&n);
while (n>0)
{
b[i]=n%16;
n=n/16;
i++;
}
while(i>0)
{
if (b[i]<10)
{
printf(b[i]);
}
else
{
switch(b[i])
{
case 10:
printf(“A”);
break;
case 11:
printf(“B”);
break;
case 12:
printf(“C”);
break;
case 13:
printf(“D”);
break;
case 14:
printf(“E”);
break;
case 15:
printf(“F”);
break;
}
//close switch
}
//close else
i–;
}
// close while
}
//close main

OUTPUT:

OUTPUT: c program for converting decimal number to hexadecimal number
Enter decimal number:25