題目描述 Description
斐波納契數(shù)列是這樣的數(shù)列:
f1 = 1
f2 = 1
f3 = 2
f4 = 3
....
fn = fn-1 + fn-2
輸入一個整數(shù)n
求fn
輸入描述 Input Description
一個整數(shù)n, n<= 40
輸出描述 Output Description
一個整數(shù)fn
樣例輸入 Sample Input
3
樣例輸出 Sample Output
2
數(shù)據(jù)范圍及提示 Data Size & Hint
n<=40
#include<stdio.h>
int main()
{
int n;
scanf("%d",&n);
int a=0,b=1,t,i;
for(i=0;i<n-1;i++){
t=a+b;
a=b;
b=t;
}
printf("%d\n",b);
return 0;
}