Python Compiler
import math num = int(input("Enter a Decimal Number: ")); copyNum = num arr = [0]*50 answer = [0]*50 value = 1 count = -1 j = 0 while(copyNum > value): count += 1 value = math.pow(8, count); arr[count] = value; count -= 1 for i in range(count, -1, -1): answer[j] = math.floor(copyNum / arr[i]) j += 1 copyNum = copyNum % arr[i] print("Octal number of %d (decimal) is " % num, end="") for i in range(0, count+1): print(answer[i], end="")
OUTPUT
Enter a Decimal Number: 9
Octal number of 9 (decimal) is 11
×

Save as Private