Write a program that takes a non-negative long as input and displays each of the digits on a
separate line. The program output should look similar to:
Enter an integer: 71345
7
1
3
4
5
Not asking to have the work done for me, but how exactly do I go about doing this? I'm extremely confused and I don't even know where to start?
1) Read the number. 2) Keep the remainder of the division to 10 in a container. 3) Divide the current number by 10. 4) Keep going until the current number becomes 0. 5) Print contents of container in reverse order.
Example:
read n = 671
add 671 % 10 == 1 to container, 671 / 10 == 67 becomes n
add 67 % 10 == 7 to container, 67 / 10 == 6 becomes n
add 6 % 10 == 6 to container, 6 / 10 == 0 becomes n, and stop
container contains: 1, 7, 6
print it in reverse: 6, 7, 1
Of course, there is a way to cheat: don't read the number as a number an integer.
Instead read it as a string, then simply print each of the characters on a separate line.
This requires no math and is much simpler, and it is why your teacher would probably consider this a form of cheating.
You can safely ignore my previous reply. Reading your original post more carefully, I saw it states that you must use a long (which is an integer, not a string).