(E) Vertical printΒΆ

Goal: I will continue practicing recursion.

Instructions: Retrieve the code template: templates/06/vertical/ -> student/06/vertical/. For automated testing, the template contains the definition RECURSIVE_FUNC. You need not care about it, and you must not change it.

In the code template, implement a recursive function print_vertical that prints the given number vertically, i.e. each digit in the line of its own.

Since the aim is to write a recursive function, loops (for or while) are not allowed.

Use only unsigned int as the type of the number to be printed. Do not change the type into a string or a vector at any phase. In addition, do not include any more libraries (besides iostream included in the code template).

Example on program execution:

Enter a number: 2019
The given number (2019) written vertically:
2
0
1
9

Tips for completing the assignment:

  • In the same way as in the previous assignment, consider first what is a trivial case and how to divide the problem into a smaller instance of the same problem (or alternatively, you can consider these things in opposite order).

A+ presents the exercise submission form here.