Homework 11: Arrays

Due: Tuesday 11/22 by 1pm

Objectives

More practice with arrays.

Assignment

Your assignment is to write a program that reads in numbers from standard input into an array and then finds and reports the maximum value of the input. After that, your program must count the number of times that the maximum value appeared on the input.

For example, if the numbers are

 2     3     9     3     7     2     3     5     6     9     7     4     9     6     4

then the maximum value is 9. So your program should report that 9 is the largest number and has appeared 3 times in the original list.

Classwork 22 is the intended starting point of this homework assignment!

Submitting. Use the script command to record yourself compiling and running your program. Run your programs several times on data files that you created. Use the cat command to show the content of your data file while you are in the script command. Submit your C source code and the typescript file as usual:

submit cs104_chang hw11 max.c
submit cs104_chang hw11 typescript


Extra Credit

For extra credit, repeat the regular assignment, except this time your program must find the the second largest value in the input. Then, report the number of times that the second largest value appears.

Note that in the example input below, the second largest value is 7 (and not 9):

 2     3     9     3     7     2     3     5     6     9     7     4     9     6     4

Finally, your program should report an error if there is no second largest value in the input. (It is possible that all the numbers in the input are the same, hence each item has the largest value.)

Submitting. Use the script command to record yourself compiling and running the your. Run your programs several times on data files that you created. Use the cat command to show the content of your data file while you are in the script command. Rename the typescript file typescript2. Then submit your C source code and typescript2 as usual:

submit cs104_chang hw11 max2.c
submit cs104_chang hw11 typescript2


Be sure to logout completely when you have finished!