Convert decimal to octal number in C, C++, Java and Python | FACE Prep
Published on 10 Mar 2020
Program to convert a number from decimal to octal is discussed here. Given a decimal number as input, which has to be converted to its equivalent octal number.
For example, decimal number 200 has to be converted to octal.
200 / 8 = 25 , rem = 0
25 / 8 = 3 , rem = 1
3 / 8 = 0 , rem = 3
The equivalent octal number of the decimal number 200 is 310.
Algorithm to convert a number from decimal to octal
- Input the decimal number.
- Divide the decimal number by 8.
- Store the remainder.
- Repeat steps 2 and 3 until the number can be divided.
- Print the reverse of the remainder, which is the octal equivalent of the decimal number.
Program to convert a number from decimal to octal
Enter a decimal number:200
Equivalent octal number :310
Time complexity: O(n)
If you have any feedback about this
article and want to improve this, please write to email@example.com