Code Competitions

Coding competition
Showing posts with label implementation of parameterised constructor. Show all posts
Showing posts with label implementation of parameterised constructor. Show all posts

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();
}