Thread: Help about recursion

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Figen View Post
    0,2,8,26,80,242,728,2186,6560,19682....how can i write these series with recursion?
    if we start k=0 and then return the function 3k+2 we can get that but I don't know how to turn this into code,can you help me about that?
    First of all, the mods here take a rather dim view of people using us to do their homework.

    You really need to make your best effort on this, on your own, and if you run into problems post your code (in code tags please) and we'll see what we can do...

    FWIW... you don't actually need recursion to solve this problem...

  2. #2
    Registered User
    Join Date
    May 2010
    Location
    Naypyidaw
    Posts
    1,314
    Mathematically
    Code:
    f(k) = 3 * f(k-1) + 2;  k > 0
    f(0) = 0;
    Edit: Just apply what tabstop said.

  3. #3
    Registered User
    Join Date
    Jul 2007
    Posts
    131
    Quote Originally Posted by CommonTater View Post
    FWIW... you don't actually need recursion to solve this problem...
    I think the hook here is to do it with recursion. I think he would've come up with some other way to implement it if his job was just to implement that series.

  4. #4
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by fronty View Post
    I think the hook here is to do it with recursion. I think he would've come up with some other way to implement it if his job was just to implement that series.
    I figured it was an assignment for some course or another.

    It's just that recursion is, to say the least, not the safest way of doing things where you have another choice on hand.

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