UMBC CS 201, Fall 06
 UMBC CMSC 201 Fall '06 CSEE | 201 | 201 F'06 | lectures | news | help Search Notes:

# Recursion

## Definition

recursion n. See recursion.

## Recursion in Mathematics

A recursive definition is one which refers to itself as in these definitions of the factorial and fibonacci functions.

n! or fact(n) is defined as:

```     fact(0) = 1
fact(n) = n * fact(n-1) , for  n > 0
```

the nth fibonacci number or fib(n) is defined as:

```     fib(0) = 1
fib(1) = 1
fib(n) = fib(n-1) + fib(n-2) , for  n > 1
```

## Recursion in Programs

A recursive function is a function that calls itself.
• Each time the function calls itself, it gets a new set of parameters and local variables.
• The parameters and local variables from a previous call to the recursive function will still be preserved until the function returns from the previous call.

### The Factorial Function in C

```int Factorial (int n)
{
if(n == 0)
{
return (1);
}
else
{
return (n * Factorial(n - 1));
}
}

```

CSEE | 201 | 201 F'06 | lectures | news | help