C Program To Convert Decimal To Hexadecimal

C Program To Convert Decimal To Hexadecimal. If you are looking for a C program to convert decimal number to hexadecimal number example, this C programming tutorial will help you to learn how to write a program for decimal to hexadecimal in C. Just go through this C programming example to learn about decimal to hexadecimal conversion.

C Program To Convert Decimal To Hexadecimal

Learn how to write a c Program to convert decimal number to hexadecimal number. Writing decimal to hexadecimal conversion program in C can be done using various techniques but here in this program, we show how to write a c program for decimal to hexadecimal in a proper way. Happy coding.

Decimal To Hexadecimal Conversion Examples

Here coding compiler will give you the decimal to hexadecimal conversion examples. A decimal number consists of base 10, i.e (0 to 9) and a hexadecimal number consists of base 16 or hex, i.e (0 to 9) to represent values zero to nine and (a, b, c, d, e, f) to represent values from ten to fifteen. Use this decimal to hexadecimal converter tool to convert numbers.

Decimal To Hexadecimal Conversion

  • Decimal – Hexadecimal
  •      10       –   A
  •     15      –    F
  •    25      –    19
  •    50     –     32
  •    75     –     4B
  •    99    –      63

Related Program: C Program to Convert Decimal to Binary

C Program For Decimal To Hexadecimal Conversion Source Code

You can copy paste the below C Program For Decimal To Hexadecimal Conversion Using while loop, in c compiler to check how the source code work. Or write your own decimal to hexadecimal C Program with the help of this below c programming tutorial.

Source Code:

/* C program to Convert Decimal to Hexadecimal - DecimalToHex.C */

#include <stdio.h>
 
int main()
{
 //variable declaration
 long decimalnum, quotient, remainder;
 int i, j = 0;
 char hexadecimalnum[100];
 
 //asking user to enter decimal value
 printf("Enter a Decimal Number: ");
 //reading user entered decimal value
 scanf("%ld", &decimalnum);
 
 quotient = decimalnum;
 
 //logc for converting decimal value to hexadecimal value
 while (quotient != 0)
 {
   remainder = quotient % 16;
   if (remainder < 10)
   hexadecimalnum[j++] = 48 + remainder;
   else
   hexadecimalnum[j++] = 55 + remainder;
   quotient = quotient / 16;
 }
 
 // displaying integer into character
 for (i = j; i >= 0; i--)
 printf("%c", hexadecimalnum[i]);
 return 0;
}

C Program To Convert Decimal Number To Hexadecimal Number Output

After you compile and run the above c program to convert decimal number to hexadecimal number, your C compiler asks you to enter the decimal number to convert into a hexadecimal number. After you enter a decimal integer, the program will be executed and give output as a hexadecimal number.

Output:

Entered decimal number is = 75

It’s Hexadecimal equivalent number is = 4B

C PROGRAMMING EXAMPLES

  1. C Program to Convert Celsius to Fahrenheit
  2. C Program To Find Absolute Value
  3. Ternary Operator Program in C
  4. C Program For Addition Table Using For Loop
  5. Denomination Program in C
  6. C Program to Print Multiplication Table 
  7. C Program Array with Example
  8. Binary Search in C Program Using Recursion
  9. Bubble Sort in C Using Pointers
  10. Bubble Sort Program in C Using Recursion
  11. Bubble Sort Program in C Using Array
  12. Bubble Sort Program in C Using Function
  13. Bubble Sort Program in C Using Linked List
  14. Stack Push Pop Program in C Using Arrays
  15. Factorial Program in C Using Pointers
  16. Factorial Program in C Using While Loop
  17. C Program For Factorial Using For Loop
  18. Factorial Program in C Using Recursion Function
  19. C Program To Reverse a String Using Pointers
  20. C Program To Swap Two Numbers Using Two Variables

One thought on “C Program To Convert Decimal To Hexadecimal

Leave a Reply

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