Common Array Algorithms
This chapter discusses how a for loop can be used to iterate over the elements of a one-dimensional array. In addition, it also discusses enhanced for loops. The chapter demonstrates the use of arrays to solve common problems such as finding sum, average, maximum, and minimum values of numbers stored in array. Pay attention to some of the common programming errors one can make while using arrays.
7. Minimum and Maximum
Answer:
array = new int[ size ];
Minimum and Maximum
The largest integer in a list of integers is the maximum value. The maximum may occur several times, but no other integer in the list is larger. Look at the following:
2, 9, 52, 23, -19, 23, 17, -45, 0
The integer 52 is the maximum. If you plot these integers on a number line the maximum is the last one on the right.
Similarly, the smallest integer in the list is the minimum. The minimum may occur several times. In the above list, the minimum is -45. The minimum is the last number on the left of the number line.
Question 7:
Examine the following collection of integers:
-20, 19, 1, 27, 5, -1, 27, 19, 5
- What is the maximum of the collection?
- How did you figure this out?