@Filename : floor.c
* @Author : Mr.Zhong
* @Date : 2018-11-02
* @Description: n级阶梯,每次走一步或2步,最多有多少种走法
* @Analysis : 斐波那契数列 -> 递归思维
***************************************************************/
#include <iostream>
using namespace std;
int getStepNum(int n)
{
if(n < 0)
return 0;
if(n == 0 || n ==1 || n ==2)
return n;
if(n > 2)
return getStepNum(n-1)+getStepNum(n-2);
}
int main()
{
int levels;
cout<<"Please enter how many levels of stairs :"<<endl;
cin>>levels;
int method = getStepNum(levels);
cout<<"There are "<<method<<" methods in total"<<endl;
return 1;
}
---------------------
作者:Tobiu 在这里插入代码片
来源:优快云
原文:https://blog.youkuaiyun.com/localhostcom/article/details/83662968
版权声明:本文为博主原创文章,转载请附上博文链接!