Flip the number
Inputs
n is a whole number from 0 to 1,000,000.
Your tasks
- Create a number
flippedthat starts at 0 and a copyrestofn. - Use a
whileloop that runs whilerestis more than 0. Each round, take the last digit offrestand put it on the end offlipped(flipped * 10 + digit). - Complete
reverseNumberso it returnsflipped. Return it, do not print it.
Example
With n = 1203, reverseNumber returns 3021.
Rules
- Zeros at the end of
ndisappear after flipping. 120 becomes 21.
Test data
TEST DATA 1: n is 1203
TEST DATA 2: n is 0
Practice focus
While loops and early exits, for when you don't know how many rounds you need. Binary search, the Euclidean algorithm and graph search are all while loops with a clear stopping rule.