描述
Redraiment小时候走路喜欢蹦蹦跳跳,他最喜欢在楼梯上跳来跳去。 但年幼的他一次只能走上一阶或者一下子蹦上两阶。 现在一共有N阶台阶,请你计算一下Redraiment从第0阶到第N阶共有几种走法。
输入
输入包括多组数据。 每组数据包括一行:N(1≤N≤40)。 输入以0结束。
输出
对应每个输入包括一个输出。 为redraiment到达第n阶不同走法的数量。
输入样例 1
1
2
0
输出样例 1
1
2
#include<stdio.h>
int getcount(int num){
int i,a,b,c;
if(num == 1){
return 1;
}
if(num == 2){
return 2;
}
if(num>=3){
a = 1;
b = 2;
for(i=3;i<num+1;i++){
c = a+b;
a = b;
b = c;
}
return c;
}
}
int main(){
int n;
while(scanf("%d",&n) && n!=0){
printf("%d\n",getcount(n));
}
}