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


Decimal to Octal

Convert Decimal to Octal in C using While Loop

This is the standard way of converting a number from decimal number system to octal number system. In this method, we are implementing the same which is depicted in the above picture.

We first need a decimal number as input then we need to divide the decimal number by 8 until the number reduces to 0 using while loop. In the meantime, we also have to concatenate each remainder according to bottom-up approach (i.e to the left of the concatenated remainders).


Decimal to octal c output

Convert Decimal to Octal in C using Recursion

The concept used in this c program is the same as the above only difference is that, it is implemented using recursion. Since recursion implements stack so the remainder gets printed from the last.


Decimal to octal C output 2

comment below your doubts.

Leave a Reply