Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- void helper(int n, vector<int> &v){
- if(n==0)return; //Base case
- //cout<<n<<" "; //Task
- v.push_back(n);
- helper(n-1,v); //Recursive step
- }
- int main(){
- //to print 5,4,3,2,1
- int n = 5;
- vector<int> v;
- helper(n,v);
- for(int i = 0; i<v.size(); i++){
- cout<<v[i]<<" ";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement