easyUnit 5 · Loops: for, while, break, continue
P14. Digit Operations
Loops: for, while, break, continue
Read a non-negative integer. Using a while loop with % and // (not string functions), find the sum of its digits, the number with its digits reversed, and how many digits it has.
Input Format
- Line 1:
n
Output Format
- Line 1:
Sum of digits: <s> - Line 2:
Reversed: <r>(for example, 1200 reversed is 21) - Line 3:
Digit count: <c>
Constraints
- 0 ≤
n≤ 10^9 - The number 0 has one digit
Sample Test Cases
Sample 1
Input
12345
Output
Sum of digits: 15 Reversed: 54321 Digit count: 5
Sample 2
Input
1200
Output
Sum of digits: 3 Reversed: 21 Digit count: 4
Submitting checks 2 sample cases and 4 hidden test cases.