- 1
How do you find 2nd largest number in unstored integer array?
Arrays in C
5 Answers
+ 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.
+ 2
You need to iterate over the array till the end.
+ 1
In which language?
+ 1
C language dear