Write a Program in Python to convert a decimal number into its corresponding octal representation.

Example:

Decimal to Octal

Recommended:

Convert Decimal to Octal in Python using Loop

The standard way to convert a decimal to octal is to divide the decimal by 8 until it reduces to 0. The remainders in the bottom-up form will give its equivalent octal value.

Output

Convert Decimal to Octal in Python using Recursion

To convert decimal into octal using recursion we need to pass the quotient (dividend/8) to the next recursive call and print the remainder (dividend%8).

Since recursion implements stack so the remainder will be printed in a bottom-up manner.

Output

Convert Decimal to Octal using oct()

Python inbuilt oct() method return the octal form of a passed number as a parameter.

It returns octal number in the form of 0oxxx, where xxx is the number form of octal representation.

Output

Comment below your doubts or suggestions if you have any.

Leave a Reply

Close Menu