Thread: need help with recursive functions

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

    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
    Cape Town
    Basically, a recursive function is a function which would call itself until a certain condition is TRUE.

    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
    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

    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.

    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!*/
    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, 05:42 AM
  3. Passing pointers between functions
    By heygirls_uk in forum C Programming
    Replies: 5
    Last Post: 01-09-2004, 06:58 PM
  4. Request for comments
    By Prelude in forum A Brief History of
    Replies: 15
    Last Post: 01-02-2004, 10: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