Results 1 to 3 of 3

Thread: Recursion

  1. #1
    allaudin's Avatar
    allaudin is offline Senior Member
    Join Date
    Apr 2013
    Posts
    271
    Rep Power
    0

    Default Recursion

    I know its not java related question but I hope you will help me to understand this ....
    Java Code:
    void f(int n) 
          {  if (n > 0) 
              {  f(n-2); cout << n <<  ; f(n-1); 
              } 
          }
    how it works ??? I know how recursion works but can't understand this one

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,193
    Rep Power
    19

    Default Re: Recursion

    Quote Originally Posted by allaudin View Post
    I know its not java related question
    Moved from New to Java.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,440
    Blog Entries
    7
    Rep Power
    20

    Default Re: Recursion

    Quote Originally Posted by allaudin View Post
    I know its not java related question but I hope you will help me to understand this ....
    Java Code:
    void f(int n) 
          {  if (n > 0) 
              {  f(n-2); cout << n << “ “; f(n-1); 
              } 
          }
    how it works ??? I know how recursion works but can't understand this one
    It looks like a cripple implementation of a Fibonacci series, i.e. f(n)= f(n-1)+f(n-2) if n > 1 else n.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Recursion?
    By Fingerz in forum New To Java
    Replies: 10
    Last Post: 01-08-2011, 02:25 AM
  2. Recursion.
    By Cruncher in forum Advanced Java
    Replies: 30
    Last Post: 05-10-2010, 01:06 PM
  3. recursion and tail-recursion differences
    By OptimusPrime in forum New To Java
    Replies: 2
    Last Post: 12-28-2009, 06:26 PM
  4. Recursion
    By kathyla18 in forum New To Java
    Replies: 2
    Last Post: 04-09-2009, 02:26 AM
  5. Recursion
    By jachandru in forum New To Java
    Replies: 1
    Last Post: 01-24-2009, 12:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •