C Program to Convert Octal Number to Decimal Number System

Write a C program to enter an octal number and convert octal number to decimal number system.
Wap in C to convert octal number to decimal number.
How to convert octal number to binary number.

Required Knowledge

Octal number system is a base 8 number system using digits 0 and 7 whereas Decimal number system is base 10 number system and using digits from 0 to 9. Given an octal number as input from user convert it to decimal number.

For Example
2015 in Octal is equivalent to 1037 in Decimal number system.

Algorithm to convert Octal to Decimal number
  • We multiply each octal digit with 8i and add them, where i is the position of the octal digit(starting from 0) from right side. Least significant digit is at position 0.
Let's convert 2015(octal number) to decimal number
Decimal number = 2*83 + 0*82 + 1*81 + 5*80 = 1024 + 0 + 8 + 5 = 1037

C program to convert a octal number to decimal number

#include <stdio.h>  
#include <math.h>    
int main() {  
    long octalNumber, decimalNumber=0;  
    int position=0, digit;  
    printf("Enter an Octal Number\n");  
    scanf("%ld", &octalNumber);  
    /* Converting octal number to decimal number */
    while(octalNumber!=0) {   
        /* get the least significant digit of octal number */

        digit = octalNumber%10;
        decimalNumber += digit*pow(8, position);    
        octalNumber /= 10;  
    printf("Decimal Number : %ld", decimalNumber);  
    return 0;  
Enter an Octal Number
Decimal Number : 1037
Enter an Octal Number
Decimal Number : 668