We need to write a C program to convert an octal number to a decimal number.


Octal to Decimal

Convert Octal to Decimal in C using Loop

An Octal number can be converted to its corresponding decimal form by summing the multiplication of each of its digits to its respective value of 8 to the power of its index (i.e position from the right – 1). Same as depicted in the above picture.

For this, we have to use a loop in which we will extract each of its digits one by one and multiply them with its respective 8x value.


octal to decimal c output

Convert Octal to Decimal in C using Recursion

The approach used in this method is the same as the above program but is implemented using recursion.

On each recursive call, we need to pass the octal number by eliminating its last digit. The recursive call will stop when there is only single left in the octal (i.e base condition).


decimal to octal c output 2

Comment below your suggestions or doubts.

Leave a Reply