Write a program that reads several integers, reverses their digits and prints the result. For example:
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).
6
720
1234
98765
6
27
4321
56789
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:
def reverse_digits(x):
int reverse_digits(int x);
reverseDigits :: Int -> Int
int reverse_digits(int x);
public static int ReverseDigits(int x)
in a public class Program
public static int reverseDigits(int x)
in a public class DigitReverse
function reverse_digits(x)
function reverse_digits (x)
def reverse_digits(x)
Submit your solution to be graded according to the following list:
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
Copyright © 2020-2022 Rudy Matela
This text is available under the CC BY-SA 4.0 license.
Originally available on cscx.org/digit-reverse