Fibonacci series using C++

Started by thiruvasagamani, Aug 07, 2008, 11:20 AM

Previous topic - Next topic

thiruvasagamani

To genearte the fibonaaci Series using C++

Here i the sample code try this

#include<iostream.h>
#include<conio.h>
#include<iomanip.h>

class fibonacci
{
   private :
      int f0, f1, fib;
   public :
      fibonacci();
      void operator++();
      void display();
};


fibonacci::fibonacci()
{
   f0=0;
   f1=1;
   fib=f0+f1;
}


void fibonacci::operator++()
{
   f0=f1;
   f1=fib;
   fib=f0+f1;
}

void fibonacci::display()
{
   cout<<fib<<endl;
}


void main(void)
{
   fibonacci obj;
   
   cout<<"fibonacci Serils length : 20"<<endl;
   
   for(int i=1; i<=20; i++)
   {
      obj.display();
      obj++;
   }

   cout<<endl;
   getch();
}
Thiruvasakamani Karnan