Home Segments Index Top Previous Next

353: Mainline

Now, suppose that you want to define a function, mean_djia, that is to accept djia as an argument, along with a day-specifying column number. The mean_djia function is to find the average of the high and low of the Dow–Jones Industrial Average on that day by computing one-half of the sum of the numbers in the first and second rows. For example, the following is to produce the average of the high and low on the third day:

mean_djia (djia, 2) 

To define mean_djia, you must include dimension information in the array specification as follows:

double mean_djia (double array[3][100], int day) { 
  return 0.5 * (array[0][day] + array[1][day]); 
} 

The declaration, double array[3][100], tells the C compiler all there is to know about the array argument.