The program to calculate the sum of the first and last elements of an array fails for arrays with only one element or empty arrays