Sep 11, 2010

Fibonnacci Series

Fibonacci series is series in which the successive element is the sum of previous two elements.
                 0 1 1 2 3 5 8 13 21 34  and so on.

Alogrithm:

  •     Read the LIMIT
  •     SET  First = -1 and Second  = 1
  •     LOOP until Second is greater than or equal to LIMIT
    • SET Sum = First + Second
    • Display the value of Sum to ouput screen.
    • SET First = Second
    • SET Second = Sum
  •    END LOOP


CodeListing
/*********************************************
      Program: Roots of Quadratic Eqn.
       Author : Vanangamudi
 *********************************************/
#include
#include

int main()
{
    int first,second,sum;
    int limit           ;
    
    cout<<"Enter the Limit\t:" ;
    cin>>limit            ;
    
    first=-1; second=1  ;
    while(sum<=limit)
    {
        sum = first + second;
        cout<<<"  " ;
        first  = second ;
        second = sum    ;        
        }        
            getch()  ;
    
}

0 comments:

Post a Comment

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | cheap international calls