Fibonacci number and recursive function

Discussion in 'C++' started by hapa_at_1, Nov 25, 2006.

  1. hapa_at_1

    hapa_at_1 New Member

    Joined:
    Oct 28, 2006
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    0
    i was looking for questions on while loops when i came across a problem that said write a program that displays fibonacci numbers
    and the code that i wrote works just fine

    Code:
    int x1=1;
    int x2=1;
    int x3;
    int x;
    cout<<"please enter the number "<<endl;
    cin>>x;
    cout<<x1<<endl<<x2<<endl;
    while (x2<x)
    {
        x3=x1+x2;
        x1=x2;
       x2=x3;
      cout<<x1<<endl<<x2<<endl;
    
    }
    
    but the second part of the question says write another program but this time using recursive funtion
    can any body please explain that to me and also how can i change my program to become a recursive function
    i can write this as a seprate funtion
    but how to find the terminating if function and how to approach this problem using recursive I have an exam coming up please help as soon as possible
     
  2. hapa_at_1

    hapa_at_1 New Member

    Joined:
    Oct 28, 2006
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    0
    i am using visual .net 2003 compiler and windows xp professsional
     
  3. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,376
    Likes Received:
    388
    Trophy Points:
    83
    I would suggest instead of getting into a solution to particular problem you should understand how recursion is done and I would suggest you read
    Recursion - Begining
    Types of Recursion - Advanced
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice