Home Segments Index Top Previous Next

246: Mainline

Thus, you can compile and run the following program:

#include  
/* Function prototype for rabbits function */ 
int rabbits (int); 
/* Function definitions requiring rabbits function prototype */ 
int previous_month (int n) {return rabbits (n - 1);} 
int penultimate_month (int n) {return rabbits (n - 2);} 
/* Function definition for rabbits function */ 
int rabbits (int n) { 
  if (n == 0 || n == 1) 
     return 1; 
   else return previous_month (n) + penultimate_month (n); 
} 
/* Test rabbits function */ 
main ( ) { 
  printf ("At the end of month 1, there is %i.\n", rabbits (1)); 
  printf ("At the end of month 2, there are %i.\n", rabbits (2)); 
  printf ("At the end of month 3, there are %i.\n", rabbits (3)); 
} 
--- Result --- 
At the end of month 1, there is 1. 
At the end of month 2, there are 2. 
At the end of month 3, there are 3.