Read a natural number n and print its mirror (the number obtained by reading its digits from right to left). The computation must be done using a recursive function.
Define a recursive function mirror(n, acc) that takes the remaining number to process and an accumulator for the result built so far. At each call, the last digit of n is appended to acc:
mirror(0, acc) = acc
mirror(n, acc) = mirror(n / 10, acc * 10 + n % 10), for n > 0For n == 0 the program prints 0.