Last active
August 8, 2020 23:46
-
-
Save pce/7c43c537a38f9af10a02f930f1e792a6 to your computer and use it in GitHub Desktop.
// g++ -std=c++11 fibo.cpp && ./a.out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
std::vector<int> f(std::vector<int> &v, int i, int n) | |
{ | |
int j = 1; | |
if (i <= n) { | |
j = v.back(); | |
v.push_back(i); | |
// std::cout << " j: " << j << "\n"; | |
i = i + j; | |
f(v, i, n); | |
} | |
return v; | |
} | |
int main() | |
{ | |
// starting with 1 and 1 rabbits | |
std::vector<int> v {1}; | |
v = f(v, 1, 144); | |
std::cout << "\nf: 0"; | |
for (const int i : v) { | |
std::cout << ", " << i; | |
} | |
std::cout << "\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment