That's not the answer to the question you originally asked because that array only has three elements. You should write code that will work for any number of elements in the array, which you can do by following the algorithm that I provided.