Last active
August 29, 2015 13:57
-
-
Save raivivek/9737148 to your computer and use it in GitHub Desktop.
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> | |
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