C Program to Convert Decimal number to Octal Number


Logic of This Program :

In this program we are accepting the decimal number from the user and decimal number is converted into the equivalent octal number with simple steps -
[box]

Steps to Convert Decimal to Octal :

  1. Accept the given decimal number
  2. If the number is less than 8 the octal number is the same
  3. If the num > 7 then Divide the number with 8
  4. Write down the remainder
  5. Do steps 3 and 4 with the quotient till that quotient is less than 8
  6. Write the remainders in reverse order (bottom to top)
  7. The resultant is the equivalent octal number to the given decimal number

[/box]
C Program - Decimal to Octal Number Conversion

C Program to Convert Decimal number into Octal Number :

Output :

Explanation of C Program :

We are dividing the number by 8 and storing the reminder in the rem[] array.

Original number is then divided by 8 and

We are repeating the steps until ‘num’ is greater than 0.

Now we are printing the reminders stored in an array in reverse order so that equivalent octal number gets printed.

Download Program :

[box]Download Code [/box]