C++ program to print Fabonacci series upto n terms

#include <iostream>
using namespace std;

int main()
{
   int i=0,j=1,sum=0,limit;

   cout<<"Enter limit for series :";
   cin>>limit;
   cout<<"The fabanacci series "<<"upto "<<limit<<" term is "<<i<<" ";

   for (int k=1;k<limit;k++)
   {

      sum=i+j;
      cout<<sum<<" ";
      i=i+j;
      j=i-j;

   }
   cout<<endl;
return 0;

}

No comments:

Post a Comment