Print Numbers
Print Numbers
Send Feedback
Given the number 'n', write a code to print numbers from 1 to n in increasing order recursively.
Input Format :
Output Format :
Constraints :
Sample Input 1 :
Sample Output 1 :
Sample Input 2 :
Sample Output 2 :
1 2 3 4
void print(int n){
//write your code here
if(n==0) return ;
print(n-1);
cout<<n<<" ";
}
#include<iostream>
using namespace std;
void print(int n){
//write your code here
if(n==0) return ;
print(n-1);
cout<<n<<" ";
}
int main(){
int n;
cin >> n;
print(n);
}
Comments
Post a Comment