Code Competitions

Coding competition

Thursday, 13 June 2013

program to generate Fibonacci series using parameterised constructor

#include<iostream.h>
#include<conio.h>
class fib
{
    private:
    int a,b,c,ca,n;
    public:
    fib()
    {
        cout<<"the fab series is ";
    }
    fib(int a1,int b1 )
    {
        a=a1;
        b=b1;
    }
    void increment()
    {
    ca=2;a=0;b=1;
    cout<<"enter the number of values ";
    cin>>n;
    cout<<a<<" "<<b;
    while(ca<n)
    {
        c=a+b;
        cout<<" "<<c;
        a=b;
        b=c;
        ca++;
    }
    }
};
void main()
{       clrscr();
    class fib k;
    k.increment();
    class fib z(0,1);
    getch();
    clrscr();
    z.increment();
    getch();
}

1 comment:

  1. C++ Program to Generate Fibonacci series

    Fibonacci Series is in the form of 0, 1, 1, 2, 3, 5, 8, 13, 21,...... To find this series we add two previous terms/digits and get next term/number.

    ReplyDelete