Skip to content

Instantly share code, notes, and snippets.

@jiunbae
Created May 2, 2015 03:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jiunbae/4e033d2a0a636ea43164 to your computer and use it in GitHub Desktop.
Save jiunbae/4e033d2a0a636ea43164 to your computer and use it in GitHub Desktop.
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
template<typename type>void print_vector(std::vector<type> vector)
{
for_each(vector.begin(), vector.end(), [](type n){static int temp = 0; cout << temp++ << " : " << n << endl; });
}
template <typename type> std::vector<type> fibonacci(type n)
{
std::vector<type>vector(n);
for_each(vector.begin(), vector.end(), [&vector](int n){static int temp = 0; vector[temp] = ((temp < 2) ? (1) : (vector[temp - 1] + vector[temp - 2])); temp++;});
return vector;
}
int main(int argc, char * argv[])
{
std::vector<int> vector = fibonacci(15);
print_vector(vector);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment