問題 A: Fibonacci
時間限制: 1 Sec 內存限制: 32 MB
提交: 557 解決: 187
[提交][狀態][討論版][命題人:外部導入]
題目描述
The Fibonacci Numbers{0,1,1,2,3,5,8,13,21,34,55...} are defined by the recurrence:
F0=0 F1=1 Fn=Fn-1+Fn-2,n>=2
Write a program to calculate the Fibonacci Numbers.
輸入
Each case contains a number n and you are expected to calculate Fn.(0<=n<=30) 。
輸出
For each case, print a number Fn on a separate line,which means the nth Fibonacci Number.
樣例輸入
1
樣例輸出
1
#include<stdio.h>
#include<algorithm>
typedef long long int LL;
int main()
{
LL f[31];
f[0] = 0;
f[1] = 1;
f[2] = 1;
for(int i=3; i<=30; i++)
f[i] = f[i-1] + f[i-2];
int n;
while(scanf("%d",&n)!=EOF)
{
printf("%d\n", f[n]);
}
return 0;
}