need help with recursive functions

This is a discussion on need help with recursive functions within the C Programming forums, part of the General Programming Boards category; Hi all .I need some one to explain what and how recursive functions work... Thanks lot...

  1. #1
    Registered User datainjector's Avatar
    Join Date
    Mar 2002
    Posts
    356

    need help with recursive functions

    Hi all .I need some one to explain what and how recursive functions work...

    Thanks lot

  2. #2
    Registered User The Dog's Avatar
    Join Date
    May 2002
    Location
    Cape Town
    Posts
    788
    Basically, a recursive function is a function which would call itself until a certain condition is TRUE.

    Eg.
    Code:
    unsigned long  factorial(int number)
    {
            return (number < 2) ? 1 : number * factorial(number - 1);
    }
    Notice that if number is not less than 2, then number is multiplied with the return value of another call to factorial().

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    And the obvious.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  4. #4
    TransparentMember correlcj's Avatar
    Join Date
    Jun 2002
    Posts
    378

    I will if you explain how the enums work around this joint, sir

    What's UP!
    RECURSION--is the ability of a function to cal itslef, either directly or indirectly.
    EX>>>.
    #include<stdio.h>

    void count_down(int n); /*function prototype*/

    int main(void)
    {
    count_down(10); /*recursive function call itself over and over again until it reaces 0*/
    return 0; /*program completed sucessfully*/
    }

    void count_down(int n) /*function definition*/
    {
    if (n) {
    printf("%d ! ", n);
    count_down(n-1); /*recursive function that counts down to 0 then prints BLAST OFF!*/
    }
    else
    printf("\nBLAST OFF\n");
    }

    Hope this example helps so complie, run it to see, huh!?!?
    "Be formless, shapeless, like water... You put water into a cup, it becomes the cup, you put water into a bottle, it becomes the bottle, you put it in a teapot, it becomes the teapot... Now water can flow, or it can crash, be water my friend."
    -Bruce Lee

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Loops or recursive functions?
    By mariano_donati in forum C Programming
    Replies: 5
    Last Post: 05-12-2008, 12:41 PM
  2. recursive function
    By technosavvy in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 04:42 AM
  3. Passing pointers between functions
    By heygirls_uk in forum C Programming
    Replies: 5
    Last Post: 01-09-2004, 05:58 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 09:33 AM
  5. How to change recursive loop to non recursive loop
    By ooosawaddee3 in forum C Programming
    Replies: 1
    Last Post: 06-24-2002, 08:15 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21