日志五
求fib数列的第n项,前几项是1,1,2,3,5,每一项都等于前面两项的和
利用循环结构,让从第三项开始,让每一项等于前两项之和
#include <iostream>
using namespace std;
int main() {int n;cin >> n;
long long fib[47] = {0, 1}; for (int i = 2; i <= n; ++i) { fib[i] = fib[i - 1] + fib[i - 2]; } cout << fib[n] << endl; return 0;
}