DAY26
Wednesday, 11 July 2012
Today we might talk about:
-
A function can call another function: program use_month_length calls
function month_length() which calls leap_year().
-
A function can call another function whose actual name is an input quantity:
euler() can call a function whose "local" name is f(x), but
whose actual name is specified by the user.
-
Global variables; we've already seen automatic variables ("local, temporary")
versus static variables ("local, but sticks around").
Programs and functions we might talk about:
-
euler.c,
a program which shows how we can write an ODE solver which will accept
the name of the right hand side function as just another input quantity.
-
leap_year.c,
a bool function which determines (TRUE/FALSE) if a given year is a leap year.
-
month_length.c,
a function which returns the number of days in a month; this function
calls leap_year();
-
p8.14.c,
a program which converts a number to a base between 2 and 16.
The program is interesting because it uses three functions,
and stores variables in global memory so that the functions
can easily share data.
-
plotter.c,
a program which makes a table of a function using n equally spaced
points from a to b. Right now, the function MUST be called "f(x)".
We'd like to make it possible for the function to be a "variable",
that is, just another input to the program.
-
use_month_length.c,
a program which calls month_length(), which calls leap_year();
Last revised on 11 July 2012.