C Program For Decimal to Hexadecimal Conversion Last Updated : 02 Aug, 2022 Comments Improve Suggest changes 3 Likes Like Report Here we will build a C Program For Decimal to Hexadecimal Conversion using 4 different approaches i.e. Using format specifierUsing modulus division operatorWithout using the modulus division operatorUsing Functions We will keep the same input in all the mentioned approaches and get an output accordingly. Input: decimal number = 45 Output: hexadecimal number = 2DMethod 1: Using the format specifier %X C // C Program to demonstrate Decimal to Hexadecimal // Conversion using the format specifier #include <stdio.h> int main() { int decimalNumber = 45; // printing hexadecimal number // using format specifier %X printf("Hexadecimal number is: %X", decimalNumber); return 0; } OutputHexadecimal number is: 2DMethod 2: Using the modulus division operator C // C Program to demonstrate Decimal to Hexadecimal // Conversion using the modulus division operator #include <stdio.h> int main() { int decimal_Number = 45; int i = 1, j, temp; char hexa_Number[100]; // if decimal number is not // equal to zero then enter in // to the loop and execute // the statements while (decimal_Number != 0) { temp = decimal_Number % 16; // converting decimal number // in to a hexa decimal // number if (temp < 10) temp = temp + 48; else temp = temp + 55; hexa_Number[i++] = temp; decimal_Number = decimal_Number / 16; } // printing the hexa decimal number printf("Hexadecimal value is: "); for (j = i - 1; j > 0; j--) printf("%c", hexa_Number[j]); return 0; } OutputHexadecimal value is: 2DMethod 3: Without using modulus division C // C Program to demonstrate Decimal to Hexadecimal // Conversion without using the modulus // division operator #include <stdio.h> int main() { int decimal_Number = 45; int i = 1, j, temp; char hexa_Number[100]; // if decimal number is not // equal to zero then enter in // to the loop and execute // the statements while (decimal_Number != 0) { int ch = decimal_Number / 16; int r = ch * 16; temp = decimal_Number - r; // converting decimal number // in to a hexa decimal number if (temp < 10) temp = temp + 48; else temp = temp + 55; hexa_Number[i++] = temp; decimal_Number = decimal_Number / 16; } // printing the hexa decimal number printf("Hexadecimal value is: "); for (j = i - 1; j > 0; j--) printf("%c", hexa_Number[j]); return 0; } OutputHexadecimal value is: 2DMethod 4: Using functions C // C Program to demonstrate Decimal to Hexadecimal // Conversion using the functions #include <stdio.h> int dec_to_hexa_conversion(int decimal_Number) { int i = 1, j, temp; char hexa_Number[100]; // if decimal number is not // equal to zero then enter in // to the loop and execute the // statements while (decimal_Number != 0) { temp = decimal_Number % 16; // converting decimal number // in to a hexa decimal // number if (temp < 10) temp = temp + 48; else temp = temp + 55; hexa_Number[i++] = temp; decimal_Number = decimal_Number / 16; } // printing the hexa decimal number printf("Hexadecimal value is: "); for (j = i - 1; j > 0; j--) printf("%c", hexa_Number[j]); } int main() { int Number = 45; // Calling the function dec_to_hexa_conversion(Number); return 0; } OutputHexadecimal value is: 2D Create Quiz Comment L laxmigangarajula03 Follow 3 Improve L laxmigangarajula03 Follow 3 Improve Article Tags : C Programs C Language C Conversion Programs Explore C BasicsC Language Introduction6 min readIdentifiers in C3 min readKeywords in C2 min readVariables in C4 min readData Types in C3 min readOperators in C8 min readDecision Making in C (if , if..else, Nested if, if-else-if )7 min readLoops in C6 min readFunctions in C5 min readArrays & StringsArrays in C4 min readStrings in C5 min readPointers and StructuresPointers in C7 min readFunction Pointer in C6 min readUnions in C3 min readEnumeration (or enum) in C5 min readStructure Member Alignment, Padding and Data Packing8 min readMemory ManagementMemory Layout of C Programs5 min readDynamic Memory Allocation in C7 min readWhat is Memory Leak? How can we avoid?2 min readFile & Error HandlingFile Handling in C11 min readRead/Write Structure From/to a File in C3 min readError Handling in C8 min readUsing goto for Exception Handling in C4 min readError Handling During File Operations in C5 min readAdvanced ConceptsVariadic Functions in C5 min readSignals in C language5 min readSocket Programming in C8 min read_Generics Keyword in C3 min readMultithreading in C9 min read Like