- 1

How do you find 2nd largest number in unstored integer array?

Arrays in C

26th Aug 2019, 11:34 AM
Khalid Rehman
Khalid Rehman - avatar
5 Respuestas
+ 3
You can either sort the array and then access the second-last (or second, depending on how you sort) element, or you can look for the biggest number by iterating over the array and updating a variable every time the current element is bigger than the currently biggest element saved in the variable, then do it again but skipping the biggest number the second time you look for it. The second solution should be more efficient due to less iterations and comparisons, but the first could be easier to implement as C provides a qsort() function which sorts an array for you.
26th Aug 2019, 12:40 PM
Shadow
Shadow - avatar
+ 2
You need to iterate over the array till the end.
26th Aug 2019, 12:39 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 1
In which language?
26th Aug 2019, 12:09 PM
rodwynnejones
rodwynnejones - avatar
+ 1
C language dear
26th Aug 2019, 12:28 PM
Khalid Rehman
Khalid Rehman - avatar