Convert decimal to octal number in C, C++, Java and Python | faceprep

Convert decimal to octal number in C, C++, Java and Python | faceprep

The 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.


Convert decimal to octal number in C, C++, Java and Python


For example, decimal number 200 has to be converted to octal.nn200 / 8 = 25 , rem = 0n25 / 8 = 3 , rem = 1n3 / 8 = 0 , rem = 3nnThe equivalent octal number of the decimal number 200 is 310.n



Convert decimal to octal number in C, C++, Java and Python

Algorithm to convert a number from decimal to octal

  1. Input the decimal number.
  2. Divide the decimal number by 8.
  3. Store the remainder.
  4. Repeat steps 2 and 3 until the number can be divided.
  5. Print the reverse of the remainder, which is the octal equivalent of the decimal number.


Convert decimal to octal number in C, C++, Java and Python

Program to convert a number from decimal to octal

@@coding::1@@


Time complexity: O(n)


Recommended Programs








convert-decimal-to-octal-number

c