Thread: Help me with recursion/recursive function!! PLZZZ!!!

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    82

    Help me with recursion/recursive function!! PLZZZ!!!

    First of all please tell me the difference between recursion and recursive function plz...

    I m a new programmer.. and i want to learn recursion/recursive fun(in which function is called in a function)

    can any one suggest me a good tutorial on the internet through which i can understand clearly and easily.. i m having my exam on Monday, and the only topic i dnt knw is this recursion... ...PLZ HELP!!!!!!!!

    I will be grateful to you on your this act.........!!!!!!

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Recursion is a type of algorithm - that is, you would use a recursive type of code, to solve the problem.

    A recursive function is the function that actually uses recursion. Usually, this will be a single function however, sometimes you will have two functions that are mutually recursive: function A calls function B, which calls function A, etc. Relatively rare, but it happens.

    Every recursive function has to have an end to the recursion. In a simple function you can still only have it call itself so many times (several hundreds to thousands, so it's a lot), but it has to have that stop in place.

    This is a very simple recursive program. Find the stop, and change the value. Do you understand all of it? Remember that ++lo will increment lo BEFORE the parameter is passed to the next call.

    Code:
    #include <stdio.h> 
    
    void printIt(int lo, int hi);
    
    int main() { //
       int limit=20;
          
             
       printIt(0,limit);
    
       printf("\n");
       return 0;
    }
    void printIt(int lo, int hi) {
       if(lo == hi) 
          return;
       else {
          printf("%2d  ",lo);
          printIt(++lo, hi);
       }
    }

  3. #3
    Registered User
    Join Date
    Nov 2011
    Posts
    82
    Quote Originally Posted by Adak View Post
    Recursion is a type of algorithm - that is, you would use a recursive type of code, to solve the problem.

    A recursive function is the function that actually uses recursion. Usually, this will be a single function however, sometimes you will have two functions that are mutually recursive: function A calls function B, which calls function A, etc. Relatively rare, but it happens.

    Every recursive function has to have an end to the recursion. In a simple function you can still only have it call itself so many times (several hundreds to thousands, so it's a lot), but it has to have that stop in place.

    This is a very simple recursive program. Find the stop, and change the value. Do you understand all of it? Remember that ++lo will increment lo BEFORE the parameter is passed to the next call.

    Code:
    #include <stdio.h> 
    
    void printIt(int lo, int hi);
    
    int main() { //
       int limit=20;
          
             
       printIt(0,limit);
    
       printf("\n");
       return 0;
    }
    void printIt(int lo, int hi) {
       if(lo == hi) 
          return;
       else {
          printf("-  ",lo);
          printIt(++lo, hi);
       }
    }
    yeah i got this concept... but it is just a basic level....

    https://docs.google.com/viewer?a=v&p...GRhM2JjZGNkY2U

    these are the 2 questions. I atleast want to learn upto this extent...

  4. #4
    Registered User
    Join Date
    Dec 2011
    Posts
    30
    Ok I looked at the link and almost rofl'd that you would ask for help on such a question good luck finding a tutorial on this and I mean that sincerely I don't think one exists personally maybe im wrong but also let me point you in a good direction:

    Cprogramming.com: Get Expert Advice

  5. #5
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Cron View Post
    Ok I looked at the link and almost rofl'd that you would ask for help on such a question good luck finding a tutorial on this and I mean that sincerely I don't think one exists personally maybe im wrong but also let me point you in a good direction:
    Well there's always.... THIS

    (Enough to keep anyone busy for a couple of months)

  6. #6
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    Right on the assignment:

    Make sure you submit your own work. Any form of collaboration will not be tolerated and case will be
    forwarded directly to the Disciplinary Committee or in the best case, negative policy (Remember -100?).
    This includes copying code snippets from the internet!

  7. #7
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    He says he's a beginner, and asks for basic info on recursion. After you give it to him, he says "No, I want help on using recursion for the Taylor Expansion series".

    Quite the joker.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Converting recursive function to tail recursive
    By ajacobs365 in forum C Programming
    Replies: 1
    Last Post: 10-30-2011, 08:15 AM
  2. Replies: 1
    Last Post: 12-03-2010, 01:54 AM
  3. Make Recursive function 'Tail-Recursive'
    By dp2452 in forum C Programming
    Replies: 7
    Last Post: 12-04-2009, 10:13 AM
  4. Recursive Function
    By Codedecode in forum C++ Programming
    Replies: 5
    Last Post: 06-07-2008, 02:14 AM
  5. recursive function
    By tonderai76 in forum C++ Programming
    Replies: 11
    Last Post: 04-21-2004, 12:49 PM