天天看點

走台階(斐波那契)

<pre class="cpp" name="code">//有n級台階,從下往上走,每次跨一級或兩級,問,走完n級台階有多少種不同的走法 
//未使用大數加法 

//#define LOCAL			//重定向語句 

#include <stdio.h>

int f(int n){
	int f=2,g=1;
	while(n>=2){
		f=f+g;
		g=f-g;
		n--;
	}
	return g;
}

int main(){
	#ifdef LOCAL
	freopen("data.in","r",stdin);
	freopen("data.out","w",stdout);
	#endif
	int sum;
	int n;
	while(scanf("%d",&n)!=EOF){
		sum=0;
		sum=f(n);
		printf("%d\n",sum);
	}
	return 0;
}