Thread: recursive function

  1. #1
    Registered User
    Join Date
    Jan 2008

    recursive function

    how can we convert an iterative function into recursive function ..

    i know few recursive functions but every time i am asked to convert an iterative function into a recursive one ...i just get perplexed...

    how do we really go for a recursive function ...i mean is there any particular way that i can try cracking an iterative function into its corresponding recursive version..

  2. #2
    uint64_t...think positive xuftugulus's Avatar
    Join Date
    Feb 2008
    You don't convert iterative functions to recusive functions. When you think what is a recursive function, think also what kind of written code it could be used to replace. Recursive conversion, is possible on loops (while, for, do - while, if goto, etc).
    void countdown(int start)
        int n = start;
            printf("Countdown to %d\n", n);
    The example function presented can be converted to a recursive.
    void countdown(int n)
            return;  /* Break recursion */
        printf("Countdown to %d\n", n);
    Of course this is a simple example but the same principle applies to most recursive transformations.
    It might interest you to know, that the task of converting recursive to non-recursive functions, is actually of much more use, and interest.
        goto johny_walker_red_label;
    johny_walker_blue_label: exit(-149$);
    johny_walker_red_label : exit( -22$);
    A typical example of programming practices.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Recursive function
    By Fork in forum C Programming
    Replies: 3
    Last Post: 10-26-2006, 11:27 AM
  2. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  3. Calling a Thread with a Function Pointer.
    By ScrollMaster in forum Windows Programming
    Replies: 6
    Last Post: 06-10-2006, 08:56 AM
  4. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM