We can convert decimal to octal numbers without using an array. So let see the approach,
1. Initialize the variables octalNum to 0 and countVal to 1.
2. Ask the user to enter the decimal number.
3. Find the remainder when the decimal number divided by 8.
//find the remainder of the entered decimal number
4. Update octal number by octalNum + (remainder * countVal )
// storing the octalvalue
octalNum = (octalNum + (remainder * countVal ));
5. Increase countVal by countVal *10.
//storing exponential value
countVal = countVal * 10;
6. Divide the decimal number by 8.
7. Repeat from the second step until the decimal number is zero.
Output:
Enter a decimal number: 74
need an explanation for this answer? contact us directly to get an explanation for this answer112