Print Numbers
PROBLEM:-Given is the code to print numbers from 1 to n in increasing order recursively. But it contains few bugs that you need to rectify such that all the test cases pass.
Integer n
Numbers from 1 to n (separated by space)
Constraints :
1 <= n <= 10000
6
Sample Output 1 :
1 2 3 4 5 6
4
Sample Output 2 :
1 2 3 4
SOLUTION:-
#include<iostream>
using namespace std;
void print(int n){
//if(n>=1&&n<=10000)
//{
static int i=1;
if(n == 1){
cout << i << " ";
return;
}
cout << i << " ";
i++;
print(n - 1);
//}
}
int main(){
int n;
cin >> n;
print(n);
}