In this pseudocode example, I’ll show you How to find the second largest number in an array.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
array arr = [10,52,64,51,23] #sample array n = array_length(arr) largest = arr[0] secondLargest = arr[0] for i=0 to i<n-1 step 1 then if arr[i] > largest then secondLargest = largest largest = arr[i] end if if arr[i] > secondLargest and arr[i] < largest then secondLargest = arr[i] end if end for print secondLargest |