Using Recursion to Write the Digits of an Integer Backwards


DUE DATE:


Take a look at this script of me running a program:

----- start of script -----
john@vega: cat digits.in
1
12
123
1234
12345
0123
1023
3201
3200
102030
john@vega: a.out < digits.in
1
1

12
21

123
321

1234
4321

12345
54321

123
321

1023
3201

3201
1023

3200
0023

102030
030201

john@vega:
----- end of script -----

Your assignment is to write a program that works like the example above.

The program must read a series of positive integers from standard input, echo each integer to standard output, and write below each integer its digits in reverse order.

The program must be able to handle as input any series of positive integers -- no matter what particular integers they happen to be and no matter how many of them there are. (That includes handling the case where there are no integers at all in the series.)

You must write a recursive function that takes a positive integer as its parameter and writes the digits of the integer backwards to the standard output. Your program must use this function to write each integer in reverse order.

The problem of writing the recursive function that prints an integer in reverse order is very similar to a problem that Carrano discusses in our textbook, and so in order to get some hints that will help you get started on the program, please check out pages 61-66.

We can discuss other details of the assignment in class.


DUE DATE: