I have stuck myself in recursive functions and searched some problems online to understand more on how they work. I came through a problem called Staircases and this was the designed code for it-
#include<bits/stdc++.h>
using namespace std;
int staircase(int n){
if(n<0){ //Base Case 1
return 0;
}
if(n==0){ //Base Case 2
return 1;
}
int count = 0;
count += staircase(n-1); //Stepping 1 step
count += staircase(n-2); //Stepping 2 step
count += staircase(n-3); //Stepping 3 step
return count;
}
int main(){
int n;
cout<<"Enter number of stairs\n";
cin>>n;
cout<<"No of ways to climb stairs are ";
cout<<staircase(n)<<endl;
return 0;
}
It would be really helpful if someone could help me understand the staircase function from "int count"{I have understood the base cases} !