C Program For Octal to Decimal Conversion Last Updated : 08 Jun, 2023 Comments Improve Suggest changes Like Article Like Report The number system is one of the ways to represent numbers. Every number system has its own base or radix. For example, Binary, Octal, Decimal, and Hexadecimal Number systems are some of the number systems and are also used in microprocessor programming. These numbers are easy to convert from one system to another system. One can convert decimal to binary, decimal to hex, decimal to octal, and vice versa. Example: Input: octal number = 123 Output: decimal number = 83 Using Format Specifier Below is the C program to convert octal to a decimal using a format specifier: C // C program to demonstrate conversion of // octal to decimal using format specifier #include <stdio.h> // Driver code int main() { int n; printf("Enter an Octal number: \n"); scanf("%o", &n); // printing the result printf("\nDecimal Representation is: %d", n); return 0; } Output Enter an Octal number: 123 Decimal Representation is: 83Without using pow() function Below is the C program to convert octal to decimal without using pow() function: C // C program to demonstrate conversion of // octal to decimal without using pow() #include <stdio.h> // Function to convert octal to decimal int octalToDecimal(int n) { int decimalvalue = 0; // Assigning base value to 1, i.e 8^0 int base = 1; int temp = n; // while loop executes the statements until the // condition is false while (temp) { // Finding the last digit int lastdigit = temp % 10; temp = temp / 10; // Multiplying last digit with appropriate // base value and adding it to decimalvalue decimalvalue += lastdigit * base; base = base * 8; } return decimalvalue; } // Driver code int main() { int octalnum = 123; printf("decimal number is %d", octalToDecimal(octalnum)); } Outputdecimal number is 83Using pow() Function Below is the C program to convert octal to decimal using the pow() function: C // C program to demonstrate conversion of // octal to decimal using pow() #include <math.h> #include <stdio.h> int Octaltodecimal(int octal) { int decimalnumber = 0, i = 0; // while loop executes the statements // until the condition is false while (octal != 0) { // Calculating equivalent decimal number // for the given octal number decimalnumber = decimalnumber + (octal % 10) * pow(8, i++); octal = octal / 10; } // printing the result return decimalnumber; } // Driver code int main() { int octalnumber = 123; // calling function printf("decimal number is %d", Octaltodecimal(octalnumber)); return 0; } Outputdecimal number is 83Standard method(Without Using Functions) Below is the C program to convert octal to decimals using the standard method: C // C program to demonstrate conversion of // octal to decimal without using functions #include <math.h> #include <stdio.h> // Driver code int main() { int octalnumber = 123, decimalnumber = 0; int i = 0; // while loop executes the statements // until the condition is false while (octalnumber != 0) { // Calculating equivalent decimal number // for the given octal number decimalnumber = decimalnumber + (octalnumber % 10) * pow(8, i++); octalnumber = octalnumber / 10; } // Printing the result printf("decimal number is: %d", decimalnumber); return 0; } Comment More infoAdvertise with us Next Article C Program For Octal to Decimal Conversion L laxmigangarajula03 Follow Improve Article Tags : C Programs C Language C Conversion Programs Similar Reads C Program For Hexadecimal to Decimal Conversion Here we will build a C program for hexadecimal to decimal conversion using 5 different approaches i.e. Using format SpecifierUsing Switch caseUsing array Using while loopUsing for loop We will keep the same input in all the mentioned approaches and get an output accordingly. Input: hexanumber = "2D 4 min read C Program For Decimal to Hexadecimal Conversion 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 accordi 3 min read C Program to Convert Decimal to Octal Given a decimal number as input, we need to write a program to convert the given decimal number into an equivalent octal number. i.e convert the number with base value 10 to base value 8. The base value of a number system determines the number of digits used to represent a numeric value. For example 3 min read Lex program for Decimal to Hexadecimal Conversion Problem: Write a Lex program for Decimal to Hexadecimal conversion. Explanation: Lex reads an input stream specifying the lexical analyzer and outputs source code implementing the lexer in the C programming language. The function yylex() is the main flex function which runs the Rule Section. Prerequ 1 min read C Program For Char to Int Conversion Write a C program to convert the given numeric character to integer.Example:Input: '3'Output: 3Explanation: The character '3' is converted to the integer 3.Input: '9'Output: 9Explanation: The character '9' is converted to the integer 9.Different Methods to Convert the char to int in CThere are 3 mai 3 min read C Program For Int to Char Conversion To convert the int to char in C language, we will use the following 2 approaches: Using typecastingUsing sprintf() Example: Input: N = 65 Output: A1. Using TypecastingMethod 1:Declaration and initialization: To begin, we will declare and initialize our integer with the value to be converted.Typecast 2 min read C Program For Double to String Conversion To convert double to string in C language, we will use the sprintf function as follows: Input: n = 456321.7651234 Output: string: 456321.7651234 Method: Using sprintf By specifying the precision in sprintf, we can convert double to string or character array with custom precision. We can use sprintf 1 min read Converting String to Long in C Here, we will see how to build a C Program For String to Long Conversion using strtol() function. Syntax: long int strtol(char *string, char **ptr, int base)The first argument is given as a stringThe second argument is a reference to an object of type char*The third argument denotes the base in whic 4 min read C Program To Convert Fahrenheit To Celsius In this article, we will learn to write a C Program to convert temperature from Fahrenheit to Celsius by applying the conversion formula to calculate the equivalent temperature in Celsius. For example, 82° in Fahrenheit is equal to 27.7° in Celcius. Formula to Convert Fahrenheit to CelsiusT(°C) = (T 1 min read Convert String to int in C In C, we cannot directly perform numeric operations on a string representing a numeric value. We first need to convert the string to the integer type. In this article, we will discuss different ways to convert the numeric string to integer in C language.Example:Input: "1234"Output: 1234Explanation: 6 min read Like