index | submit | rank | book

digit-reverse – Reverse decimal digits

Write a program that reads several integers, reverses their digits and prints the result. For example:

Reversing the digits of 720 and 1234

Input and Output

Input will consist of several lines each with a number d where 0 ≤ d ≤ 1 000 000 000. You should ignore leading zeroes on d if they are present.

For each line of input, output should contain a single line with a number b with the reversed digits of d. Do not print leading zeroes on b.

Input is terminated by the end-of-file (EOF).

Example input

6
720
1234
98765

Example output

6
27
4321
56789

The “reverse digits” function

Your program should be implemented using a “reverse digits” function that receives one integer and returns an integer with the reversed digits. Please refer to the information for the chosen language:

Scoring

Submit your solution to be graded according to the following list:

Hints

If you have difficulty with this exercise, try digit-sum or digit-count first.

try first: digit-count digit-sum oddeven

try next: digit-palindrome

index | submit | rank | book

Copyright © 2020-2022 Rudy Matela
This text is available under the CC BY-SA 4.0 license.
Originally available on cscx.org/digit-reverse