What is recursion explain with example?

Recursion is when a function (procedure) calls itself.
Example:

int Fib (int n)
{
if ((n==1)(n==0))return 1;
else return Fib(n-1) + Fib(n-2);
}
+ 22 others found this useful
Thanks for the feedback!
Follow

What was the most important lesson you learned from being on Survivor?

View Full Interview
In Bonds

Basics of Treasury Bonds and Securities Explained

Choosing the right investment is never an easy decision. What is the safest route? What is likely to yield the greatest return with the smallest risk? Are treasury bonds safe? (MORE)
In History

A Very Short Explanation of the Internet

It may seem strange, but sometimes there is a need to explain something that is so ubiquitous that you might think that it does not need an explanation. However, to explain th (MORE)

Explaining Asperger's Syndrome to Your Other Children

Having a child with Asperger's Syndrome means dealing with the reactions that follow his unusual physical and social movements. Explaining Asperger's to children helps them un (MORE)

Autism Awareness: Explaining Autism to Young Children

Explaining autism to children is a necessary part of introducing children to social situations, such as those they encounter in the park, at school or in clubs. Autism is a ve (MORE)

Straight Talk: Explaining ADHD to Children

Attention deficit hyperactivity disorder is a common condition that has the potential to severely affect how a child interacts with those around him. To make it easier both on (MORE)

Understanding Your Cholesterol Results: An Explanation for the Average Joe

It's not new that the risks of high cholesterol are not good. But do we all really understand when the cholesterol results are explained to us? Not many people do understand a (MORE)
In Physics

Explain the process of refraction and an example?

Refraction is the phenomena that occurs when a ray of light changes direction when it passes through a medium with a different refractive index. This is observable as by subm (MORE)

Can Explain with an example to the default constructor?

The following example shows a Lamborghini class with two constructors: class Lamborghini { Lamborghini() { } Lamborghini(String name) { } } Will the compiler put in (MORE)

Write a example of recursion?

Following function calculates factorial of a number using recursion.   unsigned int factorial(unsigned int a) { if (a == 1) return 1; else { a *= factorial(a-1) (MORE)