题解 | #Fibonacci(递推法)#
Fibonacci
http://www.nowcoder.com/practice/17ad6908e36a49f4b06ea96936e8bb25
#include<iostream>
using namespace std;
//递推法求斐波那契数
//需要将中间值进行存储
const int MAXN = 35;
int fibonacci[MAXN]; //存储斐波那契数
void Initial(){
fibonacci[0] = 0;
fibonacci[1] = 1;
for(int i = 2; i < MAXN; ++i){
fibonacci[i] = fibonacci[i -1] + fibonacci[i - 2];
}
}
int main(){
Initial();
int n;
while(scanf("%d",&n) != EOF){
printf("%d\n",fibonacci[n]);
}
return 0;
}