81. Python Program to Convert Decimal number into Octal number.
How does this program work?
- This program is used to convert given Decimal number into equivalent of Octal number using Python.
- That means convert number with base value 10 to base value 8.
- The integer entered by user will store in one variable. Divide that number by 8.
- Store the remainder when the number is divided by 8 in an array, Repeat the above step until the number is greater than zero.
Here is the code
def decToOctal(n):
num = [0] * 100;
i = 0;
while (n != 0):
num[i] = n % 8;
n = int(n / 8);
i += 1;
for j in range(i - 1, -1, -1):
print(num[j], end = "");
n = int(input( "Enter an integer number: "))
print("The equivalent Octal number is : ",end='')
decToOctal(n)