Doubt to convert decimal to octal

in solution u have used string and u hv not taught us. can u send any other solution to this problem

You can do it the same way you do for decimal to binary conversion as follows:

  1. Store the remainder when the number is divided by 8 in an array.
  2. Divide the number by 8 now
  3. Repeat the above two steps until the number is not equal to 0.
  4. Print the array in reverse order now.

Appears similar?
To understand this, you have to understand the concept of number systems.

I won’t go in depth.

The radix of Decimal numbers is 10. Confusing?
It means, each digit in decimal number system can take any of the 10 possible values i.e. 0-9.

Similarly, Binary numbers have 2 radix i.e. each digit is represented by either 0 or 1.
and Octal are radix 8 i.e. 0-7.

Thus, while converting a decimal number to any other number system or other radix, we repeatedly divide it with that radix and then print it in reverse order.

Hope, this would help.