Page t051, go to NEXT,
PREVIOUS, INDEX
Recursion
A function can call itself
int stirling (int n, int k)
{
if (n < k) return 0;
if ( (k == 0) && (n > 0) ) return 0;
if (n == k) return 1;
return k * stirling (n-1, k) + stirling (n-1, k-1);
}
- each { } block creates a new scope
- variables are declared and initialized in a scope and deleted when
execution leaves this scope
Exercise: write a function that computes factorial of a number
C Course, 22-jan-1997,
Peter Klok,
pfk@hef.kun.nl