Because you are counting up, not down:
for(int i=n-1; i>=0; i++){
So you start with the last element and then move to the non-existent one after that.
Try "--" instead of "++"
To be honest, you would have spotted that for yourself in under a minute if you had run that code in the debugger - I'd strongly recommend that you get used to using that, as it's your best friend in development and it's easier to get used to it with simple code like this than with a 100,000 line behemoth later!