UMBC CS 201, Fall 05
UMBC CMSC 201 Fall '05
CSEE | 201 | 201 F'05 | lectures | news | help

Recursion

Definition

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.

The Factorial Function in C

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





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

Last Modified - Saturday, 05-Nov-2005 11:22:37 EST