#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();
}
#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();
}
C++ Program to Generate Fibonacci series
ReplyDeleteFibonacci 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.