Finding the largest and smallest elements of an array

Objective

  • Define the problem by constructing an algorithm using pseudocode
  • Show a check of your solution with test data for at least two valid test cases

Find the largest element of an array

In this example. the elements of an array are searched to determine which element is the largest. The algorithm starts by putting the first element of the array into the variable called largest_element. and then looks at the other elements of the array to see if a larger value exists.

The largest value is then printed.

Find_largest_element
Set largest_element to array(0)
DO index = 1 to number_of_elements

ENDDO
Print largest_element
END
  1. Change the solution above to find the smallest element of an array
  2. Combine the solutions above to find both the largest and smallest elements of an array