CIS 15BG Assignment 3
pointers, arrays, and functions
Write a program that creates a table containing random numbers, and finds the minimum and maximum values in each column.
In main, declare the following:
- pointer to the data table
- pointer to the minimums
- pointer to the maximums
- number of rows
- number of columns
The data table will be the table containing random numbers.
The maximums will be a one-dimensional array containing the maximum value in each column.
The minimums will be a one-dimensional array containing the minimum value in each column.
The first subordinate function, called from main, will allow the user to specify the number of rows and the number of columns in the array.
The second subordinate function, will be called only once from main. It will use malloc() to obtain space for the table and the minimums and maximums arrays; the data array will be of the size specified by the user, and will contain integers; the minimums array will be a one-dimensional array with the number of columns specified by the user; the maximums array will be the same size and type as the minimums array.
The third subordinate function, called from main, will fill the data array with random integers in the range of 1 through 999. Do NOT seed the random number generator.
The fourth subordinate function, called from main, will find the maximum entry in a column of the data array, and save it in the corresponding column in the maximums array; similarly, it will fill in the minimums array.
The fifth subordinate function, called from main, will print the size of the data array, the data array, the minimum value from each column and the maximum value from each column, in neat format.
The sixth subordinate function will free the space obtained from the heap.
Note that you do not know the size of the table when the program begins. Thus, you cannot declare a two dimensional array, because you must know the number of columns in advance, in order to be able to do this. Because you cannot use a two dimensional array, you must keep the table in a one dimensional array. Compute where you put each row in your one dimensional array using pointer arithmetic. The two dimensional system of subscripts will not work; calculate your own addresses.
Test you program twice, using the following sizes:
- 3 rows and 4 columns
- 5 rows and 6 columns