3.2 recursive algorithm to learn of stair climbing

A title
Title two

Export

A different number of moves, each row corresponding to an input line of output

Sample input

5
8
10

Sample Output

8
34
89

Block

#include<iostream>
using namespace std;
int stair(int n){//表示n级台阶有多少种走法
    if( n == 0 )
        return 1;
    if( n == 1 )
        return 1;
    return stair( n-1 ) + stair( n-2 );
}
int main(){
    int n;
    while(cin>>n)
        cout<<stair(n)<<endl;
    return 0;
}

Released six original articles · won praise 1 · views 15

Guess you like

Origin blog.csdn.net/weixin_42503072/article/details/104400331