![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
Another virtue of function abstraction is that you can
improve more
easily how a computation is done. You might decide, for example, that it
is wasteful for your doubling_time
function to divide 72.0
by
the rate twice. Accordingly you might decide to do the division just once,
using a variable, named result
, to hold on to the value:
double doubling_time (double r) { double result = 72.0 / r; printf ("The doubling time for rate %f is approximately %f years.\n", r, result); return result; }
Again, you do not need to bother to find all the places where the volume is
computed using the doubling_time
function; you need only to change
the doubling_time
function's definition.