Problem: Write a C program to convert an octal number to a decimal number.


Octal to Decimal using While 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).

Octal to Decimal

To implement the same in C, we will use while loop to sum the digits of the number after multiplying them with their respective 8x values.


octal to decimal c output

Octal to Decimal 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

In this tutorial, we learned to convert an octal number to its corresponding decimal representation using c programming language.

Leave a Reply