← Back to Loops
Question 403
Reverse The Digits
Reverse The Digits
Read a positive whole number and print its digits in reverse order as a single number (for example 1230 becomes 321, since the leading zero is dropped). Use a while loop that runs while the number is above 0: the remainder operator % with 10 gives the last digit, integer division // by 10 drops it, and the reversed value grows as reversed_num * 10 + digit. Print Reversed: <value>. Input: one integer, no prompt. Do not convert the number to a string or use slicing.
Expected Output:
Reversed: 4321= newline. The output ends with a newline — print one after the last line.
Hints4 available
Sign in to use hintsTopics:
Loops
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Ctrl+Space to expand shortcuts (pr, inp, def)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.