VOOZH about

URL: https://www.geeksforgeeks.org/c/c-program-for-hexadecimal-to-decimal-conversion/

⇱ C Program For Hexadecimal to Decimal Conversion - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

C Program For Hexadecimal to Decimal Conversion

Last Updated : 2 Aug, 2022

Here we will build a C program for hexadecimal to decimal conversion using 5 different approaches i.e.

  1. Using format Specifier
  2. Using Switch case
  3. Using array 
  4. Using while loop
  5. Using for loop

We will keep the same input in all the mentioned approaches and get an output accordingly.

Input: 

hexanumber = "2D" 

Output: 

decimalnumber = 45

Method 1: Using format specifier

The format specifier %x represents the Hexadecimal number

Output

👁 Hexadecimal to decimal conversion output
Output

Method 2: Using switch case


Output
Decimal value is: 45

Method 3: Using Array


Output
Decimal Number : 45

Method 4: Using while loop


Output
Hexadecimal number = 2D
Decimal number = 45

Method 5: Using for loop


Output
Hexadecimal number = 2D
Decimal number = 45
Comment