当前位置: 代码迷 >> 综合 >> [WikiOI] 2.5.2 Fibonacci数列
  详细解决方案

[WikiOI] 2.5.2 Fibonacci数列

热度:26   发布时间:2023-12-09 05:59:12.0

[Problem]

斐波纳契数列是这样的数列:

f1 = 1

f2 = 1

f3 = 2

f4 = 3

....

fn = fn-1 + fn-2

 

输入一个整数n

求fn


[Solution]

#include <iostream>
using namespace std;int main(){int array[41];array[1] = 1;array[2] = 1;int n;cin >> n;for(int i = 3; i <= n; ++i){array[i] = array[i-1] + array[i-2];}cout << array[n] << endl;return 0;
}