Friday, April 4, 2014

C++ Program to generate n number of Fibonacci series

C++ Program to generate n number of Fibonacci series

In mathematics, the Fibonacci numbers or Fibonacci series or Fibonacci sequence are the numbers in the following integer sequence:
1,1,2,3,5,8,13,21,34,55,89,144….
or (often, in modern usage):

0,1,1,2,3,5,8,13,21,34,55,89,144……(sequence A000045 in OEIS)

By definition, the first two numbers in the Fibonacci sequence are 1 and 1, or 0 and 1, depending on the chosen starting point of the sequence, and each subsequent number is the sum of the previous two.                                                wikipedia



#include<iostream.h>
class febin
{
int f,s,ne,n,i;
public:
void input()
{
cout<<"How many elements do you want in febinocci series\n";
cin>>n;
}
void calculation()
{
f=0;
s=1;
cout<<f<<" ";
for (i=1;i<n;i++)
{
ne=f+s;
cout<<ne<<" ";
s=f;
f=ne;
}
}
};
void main()
{
clrscr();
febin a;
a.input();
a.calculation();
}

No comments:

Post a Comment