# answer me plezz ?????

Printable View

• 03-03-2008
khushal
answer me plezz ?????
Recursion : What is Function Recursion
• 03-03-2008
swgh
A recursive function is a function that calls itself. It uses a base step and a recursive step.
• 03-03-2008
khushal
need further explanation
Can you explain it by giving a simple example of addition or multiplication plezz
• 03-03-2008
rags_to_riches
• 03-03-2008
MacGyver
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.
• 03-03-2008
matsp
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
• 03-03-2008
khushal
need further explanation for:
need and explanation about addition and subtraction of numbers entered through an 1 D array
• 03-03-2008
Fordy
Do your own homework