Thursday, September 12, 2019

C++: Find the second largest element in an array

In this tutorial, we will see how to find the second largest element in an array. There are different ways to do it- like sorting the array first in descending order and then printing the second element or by double iteration- first for finding the largest element and second for finding the number just less than the largest. But there is one way to find the second largest element just in single iteration. Here is the code for the program.


Output: The second largest element is 8.

No comments:

Post a Comment