Home Segments Index Top Previous Next

97: Mainline

In the following example, the definition of the doubling_time function appears in a complete program:

#include  
/* Define doubling_time first */   /**/ 
double doubling_time (double r) {  /**/ 
  return 72.0 / r;                 /**/ 
}                                  /**/ 
main ( ) { 
  double r = 5.0; 
  printf ("Your money doubles in about %f years at %f percent.\n", 
                                       doubling_time (4.0), 
                                                   4.0); 
  printf ("Your money doubles in about %f years at %f percent.\n", 
                                       doubling_time (r), 
                                                   r); 
  printf ("Your money doubles in about %f years at %f percent.\n", 
                                       doubling_time (r + 1.0), 
                                                   r + 1.0); 
} 
--- Result --- 
Your money doubles in about 18.000000 years at 4.000000 percent. 
Your money doubles in about 14.400000 years at 5.000000 percent. 
Your money doubles in about 12.000000 years at 6.000000 percent.