UMBC CS 201, Fall 98
UMBC CMSC 201 & 201H Fall '98 CSEE | 201 | 201 F'98 | 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.

factorial function in C

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






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

Sunday, 06-Dec-1998 18:01:49 EST