C++ program to print Febonacci series by using Class.

Febonacci Series : This is a type if series of numbers in which each number (Fibonacci number) is the sum of the two preceding numbers. The simplest is the series 1, 1, 2, 3, 5, 8,…… etc.

 

 

Step 1: Let’s open turboC++ and write the following Code:

 

 

//Code:

 

 

#include<iostream.h>

#include<conio.h>

class series

{

private:

int n,a;

float c,i,j;

public:

void input();

void display();

};

void series::input()

{

 cout<<”enter range of series:”;

 cin>>n;

 cout<<”enter first number:”;

 cin>>i;

 cout<<”enter second number:”;

 cin>>j;

for(a=1;a<=n;a++)

{

 c=i+j;

 i=j;

 j=c;

}

 cout<<”\n”<<c;

}

void series::display()

{

 cout<<”\n”;

}

void main()

{

 series f;

 f.input();

 f.display();

 getch();

}


Now, Run the program to see Output.

 

 

Output:

 

output

 

Happy coding.

 

 

Tags: , , ,

Comments are closed.