C++ || Snippet – How To Find The Highest & Lowest Numbers Contained In An Integer Array

Print Friendly, PDF & Email

This page will consist of a simple demonstration for finding the highest and lowest numbers contained in an integer array.


Integer Arrays
For Loops

Finding the highest/lowest values in an array can be found in one or two ways. The first way would be via a sort, which would obviously render the highest/lowest numbers contained in the array because the values would be sorted in order from highest to lowest. But a sort may not always be practical, especially when you want to keep the array values in the same order that they originally came in.

The second method of finding the highest/lowest values is by traversing through the array, literally checking each value it contains one by one to determine if the current number which is being compared truly is a target value or not. That method will be displayed below.

NOTE: On some compilers, you may have to add #include < cstdlib> in order for the code to compile.

The highlighted lines are sections of interest to look out for.

The code is heavily commented, so no further insight is necessary. If you have any questions, feel free to leave a comment below.

Once compiled, you should get this as your output

Original array values
10 14 1 94 29 25 7 95 11 17 6 71 100 59
These are the highest and lowest array values:
Highest: 100
Lowest: 1

Leave a Reply