Skip to content

Instantly share code, notes, and snippets.

@raivivek
Last active August 29, 2015 13:57
Show Gist options
  • Save raivivek/9737148 to your computer and use it in GitHub Desktop.
Save raivivek/9737148 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <vector>
using namespace std;
void calcFibonacci(vector<int> &fibonacci, int no_of_terms) {
fibonacci.push_back(0);
fibonacci.push_back(1);
for(int i=2 ; i < no_of_terms; ++i) {
fibonacci.push_back(fibonacci[i-1]+fibonacci[i-2]);
}
/* Print the elements if you want */
cout << fibonacci[2] << " " << fibonacci[3] << endl;
}
int main() {
/* This vector contains the elements of Fibonacci series */
vector<int> fibonacci;
int no_of_terms;
cout << "Enter the no of terms " << endl;
cin >> no_of_terms;
calcFibonacci(fibonacci,no_of_terms);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment