问题:一老师爬楼梯,楼梯有n阶,一次只能走1阶或2阶,请问有几种走法?
#include <iostream> using namespace std; int fun(int a) { static int i = 0; if(a==0||a==1) return 1; return fun(a-1)+fun(a-2); } int main() { int a = 4; cout<<fun(a)<<endl; return 0; }
运行结果:
5
原文地址:https://www.cnblogs.com/caozewen/p/12207894.html
时间: 2024-10-19 09:27:17