How to find the Second largest element in an Array?

Example 1: Given input array is {12, 35, 1, 10, 34, 1}

Output: The second largest element in array is 34.

The loop will find the largest element present in the array which is smaller than the largest element.

Start traversing the array from array[1],

i) If the current element in array say arr[i] is greater than first.

Then update first and second as, second = first & first = arr[i]

ii) If the current element is in between first and second

Then update second to store the value of current variable as second = arr[i]

iii) Return the value stored in second.