TITLE:-
Staircase
PROBLEM:-
Integer N
Integer W
1 <= N <= 30
4
7
5
13
SOLUTION:-
#include <iostream> using namespace std;
int staircase(int n){
/* Don't write main().
* Don't read input, it is passed as function argument.
* Return output and don't print it.
* Taking input and printing output is handled automatically.
*/
if(n==1)
return 1;
if(n==2)
return 2;
if(n==3)
return 4;
if(n>3)
{
return staircase(n-1)+staircase(n-2)+staircase(n-3);
}
}
int main() {
int n, output;
cin >> n;
output=staircase(n);
cout<< output <<endl;
}
This is dummy text. It is not meant to be read. Accordingly, it is difficult to figure out when to end it. But then, this is dummy text. It is not meant to be read. Period.
If you have any doubts then please let me know... ConversionConversion EmoticonEmoticon