Fibonacci Series Using C++ Language

Fibonacci Series : It is also known as Fibonacci numbers or Fibonacci sequence. Actually it is sequence integers number like this 

0  1  1  2  3  5  8  13  21  34  55  83 ....

After first two numbers 0 and 1  , every consecutive number is the summation of previous two numbers.For more Visit here .

Algorithm:

First we have to look what is the common thing which is repeating itself. You can see that after first two numbers , the next numbers have some common thing , every next number is the summation of the previous two.



Program code:

#include<iostream>
#include<conio.h>
using namespace std ;

int main()
{
int a , b , c , result ;
int i = 0,input ;
a=0  ;
b=1  ;
c= a + b ;
cout<< "Enter input  "<<endl << endl ;
cin >> input ;   // input from user
cout<< "  Fibonacci series is  =   "<< a << "  "<< b <<  "  " << c ;
while(c  < input )
   {
      a = b     ;
  b = c     ;
  c = a + b ;
  cout<< "  " << c ;
   }

getch();
}

Output:


click pic to view large size

Hope that you will find this helpful.


No comments:

Post a Comment

Please disable your ad blocker to support this website.

Our website relies on revenue from ads to keep providing free content.