Skip to content

Commit a523b21

Browse files
authored
Create NNaturalNum.java
1 parent d5dbfda commit a523b21

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
Given is the code to print numbers from 1 to n in increasing order recursively.
3+
4+
Input Format :
5+
Integer n
6+
7+
Output Format :
8+
Numbers from 1 to n (separated by space)
9+
10+
Constraints :
11+
1 <= n <= 10000
12+
13+
Sample Input 1 :
14+
6
15+
Sample Output 1 :
16+
1 2 3 4 5 6
17+
18+
Sample Input 2 :
19+
4
20+
Sample Output 2 :
21+
1 2 3 4
22+
*/
23+
24+
public class NNaturalNum {
25+
26+
public static void print(int n){
27+
if(n == 0){
28+
return;
29+
}
30+
else
31+
{
32+
print(n - 1);
33+
System.out.print(n+" ");
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)