Quote:
The problem is the code will output the numbers in reverse. I.e if I input 789 it will output 9 8 7.
The modulo (%) operator gets digits from right to left but you want digits from left to right.
If you handle input as an integer:
- To reverse the list of digits, you can use an array, a stack, a vector ...
- You can also use a recursive function to treat the input.
:You can also handle the input as a string
- and treat each char of the string individually.