• + 1 comment

    you are doing the loop thing wrong. Firstly i should be initialized to n-1 , then it should be i>0 . Now a[i+1]=a[i]; is wrong. It should be a[i]=a[i-1] because you are running loop from end and not from starting.