How to get the highest number in an array? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to get the highest number in an array?

How do i establish the highest number in an array of numbers it could be multi dimension or single dimension

19th Oct 2018, 4:50 AM
Nelson Mandela
Nelson Mandela - avatar
1 Answer
+ 3
[meta, note] Arrays are allocated as contiguous* memory. Because of this--plus you do not care where in the array that highest value is located--you can walk a multidimensional array as if it were 1-dimensional. That is, a 3x3 array is 9 elements long, so you can loop from 0..8 and hit exactly the same elements. * Adjacent, with no gaps C/C++ tip: How to loop through multi-dimensional arrays quickly (9 methods) http://nadeausoftware.com/articles/2012/06/c_c_tip_how_loop_through_multi_dimensional_arrays_quickly Methods 8 and 9 are of the type I'm describing.
19th Oct 2018, 5:05 AM
Kirk Schafer
Kirk Schafer - avatar