Search

27 January, 2016

Fibonacci series in c++

#include<iostream>
using namespace std;

int main(){

 int n, first = 0, second = 1, third;

 cout<< "enter the number of terms " << endl;
 cin >> n;

 cout << "first "<< n << " fibonaccy series"<< endl;

 for(int i = 1; i <= n ; i++){
    if(i <= 1){
        third = i;
    }
    else{
      third = first + second;
      first = second;
      second = third;

    }
cout << third << " ";
 }

return 0;
}


First 6 fibonacci series are 

1 1 2 3 5 8