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

c program to convert decimal number to hexadecimal number
c program to convert decimal number to hexadecimal number

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”);
Convert_hexadecimal(num);
}

void Convert_hexadecimal(int n)
{
while (n>0)
{
int i=0,b[100];
b[i]=n%16;
n=n/16;
i++;
}
printf(“\n Hexadecimal is: “);
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[100];
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++;
}
printf(“\n Hexadecimal is: “);
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
Hexadecimal is: 19

Other programs:

Static variable scope
Register variable scope
External variable scope
Automatic variable scope
amicable number
Prime number
Perfect number
Palindrome number
Strong number
Find Factorial 
Biggest Number
Average of n numbers
convert decimal number to octal
decimal number to hexadecimal
decimal number to binary
simple interest
compound interest
Add sparce matrices
Add matrices
 file copying
Palindrome string
Reverse string
String length
Replace characters in string
substring or not using arrays
First occurrence of character in string
Last occurrence of character in string
Convert to uppercase
Convert to lowercase
Concatenate strings 
Compare strings
Generate Employee payslips
Count students scoring marks>50%
convert weight into grams

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *