Thread: Help about recursion

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Dec 2010
    Posts
    20
    you are not giving anything here...there is no interaction with user.

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Look at my example, note:

    1) You call the recursive function ONE time, only. After that ONE call in main(), the recursive function calls itself the correct number of times, because you set up the base case. That tells it when it should end.

    Remove your for loop in main() which calls the recursive function.

    2) The printing is done INSIDE the recursive function, not in main().

    3) You need an if statement in the recursive function, to give it the logic when it should return. You don't have that if statement in yours yet.

  3. #3
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    I found this thread relevant to your question about recursion...
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by brewbuck View Post
    I found this thread relevant to your question about recursion...
    I was going to do this, but once I got started, I didn't know how to stop. I had to fork() so I could reply.


    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Oh you jokers, Brewbuck and Quzah!

    Thanks for the laughs.

  6. #6
    Registered User Char*Pntr's Avatar
    Join Date
    Sep 2007
    Location
    Lathrop, CA
    Posts
    198

    Thumbs up

    Quote Originally Posted by brewbuck View Post
    I found this thread relevant to your question about recursion...

    Quote Originally Posted by quzah View Post
    I was going to do this, but once I got started, I didn't know how to stop. I had to fork() so I could reply.

    Quzah.


    LMAO!

  7. #7
    Registered User
    Join Date
    Sep 2004
    Posts
    124
    A bit like if you go to Google and do a search for Recursion.
    I think you can put a signature here.

  8. #8
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by Figen View Post
    you are not giving anything here...there is no interaction with user.
    That's not how functions work. You give them something (or some things), and they give you something back. For instance, if I do
    Code:
    log(10)
    I give the function the value 10, as input, and it gives me back the result, 2.302585 or so. So when you call recursion(6), you are giving the function 6, and you had better be expecting the number 728 back from it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Template Recursion Pickle
    By SevenThunders in forum C++ Programming
    Replies: 20
    Last Post: 02-05-2009, 09:45 PM
  2. Recursion... why?
    By swgh in forum C++ Programming
    Replies: 4
    Last Post: 06-09-2008, 09:37 AM
  3. Recursion
    By Lionmane in forum C Programming
    Replies: 11
    Last Post: 06-04-2005, 12:00 AM
  4. a simple recursion question
    By tetra in forum C++ Programming
    Replies: 6
    Last Post: 10-27-2002, 10:56 AM
  5. stack and recursion help needed!
    By LouB in forum C++ Programming
    Replies: 3
    Last Post: 07-01-2002, 02:19 PM