answer me plezz ?????

This is a discussion on answer me plezz ????? within the C++ Programming forums, part of the General Programming Boards category; Recursion : What is Function Recursion...

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    3

    Question answer me plezz ?????

    Recursion : What is Function Recursion

  2. #2
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,475
    A recursive function is a function that calls itself. It uses a base step and a recursive step.
    I'm just trying to be a better person - My Name Is Earl

  3. #3
    Registered User
    Join Date
    Mar 2008
    Posts
    3

    need further explanation

    Can you explain it by giving a simple example of addition or multiplication plezz

  4. #4
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,639

  5. #5
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    Consider a factorial of a number. Let's go with this as a definition: n! = n * n-1 * n-2 .... * 1

    Now let's talk about 5 factorial, written as "5!".

    5! can be written two ways.

    1. 5! = 5 * 4 * 3 * 2 * 1
    2. 5! = 5 * 4!


    The first view is iterative. The second is recursive.

    There's your example.

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    A recursive multiplication (very stupid implementation, but it does the required task):
    Code:
    int mul_rec(int x, int y)
    {
       if (x == 0) return 0;
       if (x == 1) return y;
       return mul_rec(x - 1, y);
    }
    The above code will only work for relatively small numbers, as there is a limit to how much stack you can use [Pedant prevention: Yes, a good compiler will probably make the tail-recursion into a loop].

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #7
    Registered User
    Join Date
    Mar 2008
    Posts
    3

    need further explanation for:

    need and explanation about addition and subtraction of numbers entered through an 1 D array

  8. #8
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,786
    Do your own homework

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Looking for constructive criticism
    By wd_kendrick in forum C Programming
    Replies: 16
    Last Post: 05-28-2008, 09:42 AM
  2. One quick question...
    By Kross7 in forum C++ Programming
    Replies: 10
    Last Post: 04-13-2007, 09:50 PM
  3. Tic Tac Toe program...
    By Kross7 in forum C++ Programming
    Replies: 12
    Last Post: 04-12-2007, 03:25 PM
  4. Game Programming FAQ
    By TechWins in forum Game Programming
    Replies: 5
    Last Post: 09-29-2004, 02:00 AM
  5. code help :)
    By Unregistered in forum C Programming
    Replies: 4
    Last Post: 02-28-2002, 12:12 PM

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