ENGR 221

Fall Semester 2007

Homework Assignment 5

Due Thursday, October 4, 2007

Write a C program, hwk5.c, that implements two programmer-defined functions with the following prototype statements. (Use this exact form)

double max(double x[NROWS][NCOLS])

void change_max(double *p, double v);

In main, declare an array v and initialize it with the following values.

Define the size of the array in preprocessor directives. In main, print out the array in the format shown above (with values placed in rows and columns consistent with its size). Modify the example at the top of p. 212 to do this. Then call the max function to find the maximum value of the array. Because it has a two-dimensional rather than a one-dimensional array as an argument, this function will not be the same as that given on p. 214; however, you may modify that function for the 2D case.

In main, print this maximum value. Then call the function change_max to increase the value of the maximum by 10 using its pointer. In main, define a pointer that points to the first element in the array. Pass this to the function. Only the maximum value should be changed; all other values in the array should remain unchanged. In main, print out the revised 2D array. Note that the function change_max has a void return type; it does not return a value to main because it changes the actual values of the arrays in memory via its pointer. Your output should look like the following:

Array v:

-4.30 6.20 1.50 8.40

2.50 7.10 -4.70 -3.20

-9.20 7.80 6.30 10.20

1.70 5.20 7.40 2.30

Maximum value of 2D array v is 10.20.

Revised array v:

-4.30 6.20 1.50 8.40

2.50 7.10 -4.70 -3.20

-9.20 7.80 6.30 20.20

1.70 5.20 7.40 2.30

Maximum value of 2D array v is 20.20.

The program must be general enough to work on any size two-dimensional array (not necessarily square). If the size or values of array v are changed in the declarations, the ONLY other change to the program should be the change in the symbolic constants in the preprocessor directive. Test your program with arrays of varying sizes.

Turn in a copy of your program with hwk5.c and your name in comment lines at the top. Copy and paste your output below the program. Do not forget to delete the output from the saved version of your program; otherwise, it will not compile when collected!

Email a completed copy of your program to both the instructor and the grader prior to the start of class on the due date. In the subject line of this email, type ENGR 221 hwk5.c. Send it as an attachment from your IPFW webmail account, which can be accessed through If you are working from home or a campus lab other than the engineering labs, you can access the file by logging into and transferring it from your homework directory to the local computer. Once the file is on the local computer, you can attach it to an email. In class, turn in a hardcopy of the program with your results appended at the bottom. Make sure the version you email does not have these appended results because it will not compile.

Grading:

Functionsproperly implemented4 pts.

Program compiles1 pts.

Comments and style2pts.

Results accurate and according to instructions3 pts.

10 pts.