Above code will only work for given set of numbers. What if there are only 3 numbers? 20 Numbers? 10000 numbers?

It is easier to determine when you are at the first number than the last number. So...