#include<iostream>
#include<vector>
using namespace std;
const int maxn = 1024;
const vector<int>* fib_seq(int size) {
static vector<int> elems;
if (size <= 0 || size > maxn)
cout << "wrong size!" << endl;
for (int ix = elems.size(); ix < size; ++ix) {
if (ix <= 1)
elems.push_back(1);
else
elems.push_back(elems[ix - 1] + elems[ix - 2]);
}
return &elems;
}
int main() {
const vector<int>* p = fib_seq(20);
for(int i = 0; i < 10; ++i)
cout << (*p)[i]<<"\t";
p = fib_seq(40);
cout <<"\n"<< (*p)[35] << endl;
}
07-06
360
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
06-19
470
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
01-16
2796
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交