C Program For Octal to Decimal Conversion
Here, we will convert the octal to a decimal using 4 different approaches in C Language:
- Using Format Specifier
- Without using pow()
- Using pow()
- Using Standard method
Input:
octal number = 67
Output:
decimal number = 55
Approach 1: Using format specifier
C
// C program to demonstrate conversion of// octal to decimal using format specifier #include <stdio.h> int main(){ int n; scanf("%o", &n;); // printing the result printf("%d", n); return 0;} |
Output:

Output
Approach 2: 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 decimalint 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 programint main(){ int octalnum = 67; printf("decimal number is %d", octalToDecimal(octalnum));} |
Output
decimal number is 55
Approach 3: Using 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 codeint main(){ int octalnumber = 67; // calling function printf("decimal number is %d", Octaltodecimal(octalnumber)); return 0;} |
Output
decimal number is 55
Approach 4: Standard method(without using functions)
C
// C program to demonstrate conversion of// octal to decimal without using functions #include <math.h>#include <stdio.h>int main(){ int octalnumber = 67, 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;} |
Output
decimal number is: 55


