6-1
(1/1 分数)
题目描述
下n级台阶,每步可下1级或2级台阶。那么从n级台阶下到地面,共有多少种不同的下台阶方案?
输入:n
输出:方案数
多行输入,每一行输入一个正整数n,表示n级台阶
输出格式每一行输出n级台阶的方案数
样例输入
1 2样例输出
1 2代码框
#include <iostream>
using namespace std;
const int Max=100;
int count_step(int temp);
int main(){
int temp;
int i=0;
int a[Max];
while(cin>>temp){
a[i]=temp;
i++;
}
for(int j=0;j<i;j++){
cout<<count_step(a[j])<<endl;
}
return 0;
}
int count_step(int temp){
if(temp==1) return 1;
else if(temp==2) return 2;
else return count_step(temp-1)+count_step(temp-2);
}