If you step through this, the code ends up accessing an out of bounds element of the array. I just added in some output statements to show how the numbers change.
I think you mean to use a[x] not a[i] in your for loop, but the while loop still tries to assign a value to an out of bounds element of the array.
beginning of while loop
i = 0
a[0] = 2.5
i = 1
a[1] = 3.5
s = 1
end of while loop
beginning of while loop
i = 1
a[1] = 2.5
i = 2
a[2] = 3.5 // this element does not exist
s = 0
end of while loop
in the for loop
a[2] = 3.5
in the for loop
a[2] = 3.5