Home Segments Index Top Previous Next

234: Mainline

Capturing the rabbit formula in the form of a C function, you have the following:

#include  
/* Define rabbits function */ 
int rabbits (int n) { 
  if (n == 0 || n == 1) 
     return 1; 
   else return rabbits (n - 1) + rabbits (n - 2); 
} 
/* Test rabbits function */ 
main ( ) { 
  printf ("At the end of month 1, there is %i.\n", rabbits (1)); 
  printf ("At the end of month 10, there are %i.\n", rabbits (10)); 
  printf ("At the end of month 20, there are %i.\n", rabbits (20)); 
} 
--- Result --- 
At the end of month 1, there is 1. 
At the end of month 10, there are 89. 
At the end of month 20, there are 10946.