Print 1 to N

Practice this coding question on Coding Gurukul.

Problem statement

A museum numbers the stops on an audio tour from one to n. Its controller uses a recursive routine to announce the stop numbers in forward order. Your task Print every integer from 1 through n, inclusive, using recursion rather than a loop to generate the sequence. Important details The sequence must be ascending, with each number appearing exactly once. Stop the recursion at a suitable base case so that neither zero nor n + 1 is printed. The input limit keeps the recursion depth modest. The judge checks the printed sequence; the use of recursion is an algorithmic requirement for practice and code review. Do not print brackets or explanatory labels. Worked example For n = 5, the tour announces 1 2 3 4 5. For n = 1, only the first stop is printed.

Input format

One integer n.

Output format

Print 1 through n separated by spaces.

Constraints

1 <= n <= 100.

Sample input

5

Sample output

1 2 3 4 5

Sign in to run or submit a solution in C++, Java or Python.