Interview Questions   Tutorials   Discussions   Programs   Videos   

C++ - Write the program for fibonacci in c++?




310
views
asked marvit August 18, 2014 11:09 AM  

Write the program for fibonacci in c++?


           

1 Answers



 
answered By bhjahnavi   0  
/* program for fibonocci series*/
#include<iostream.h>
 
using namespace std;
 
main()
{
  int n, c, first = 0, second = 1, next;
 
  cout << "Enter the number of terms of Fibonacci series you want" << endl;
  cin >> n;
 
  cout << "First " << n << " terms of Fibonacci series are :- " << endl;
 
  for ( c = 0 ; c < n ; c++ )
  {
   if ( c <= 1 )
     next = c;
   else
   {
     next = first + second;
     first = second;
     second = next;
   }
   cout << next << endl;
  }
 
  return 0;
}

flag   
   add comment

Your answer

Join with account you already have

FF

Preview


Ready to start your tutorial with us? That's great! Send us an email and we will get back to you as soon as possible!

Alert