ARRAY CODE HELP

Su
Last edited on
First sort the array. You can use the sort function from the algorithm header. Supply the sort function with overloaded begin and end functions. It will be sorted in ascending order, so the 2nd last element will be the 2nd largest.
1
2
3
4
const size_t size{10};
int listArray[size] = {2,5,3,1,8,4,6,7,10,9};
sort(begin(listArray), end(listArray)); // sort and end are overloaded for arrays
cout << "2nd Largest: " << listArray[size-1] << endl;
Topic archived. No new replies allowed.