What is the output that you are expecting from the above code ?
It is working fine.
So for
First Iteration
i = 1
a[1] = 0
array = {1,0,3,4,5,6,7,8}
Second Iteration
i=0
a[0] = 0
array = {0,0,3,4,5,6,7,8}
Third Iteration
i=3
a[3]=0
array = {0,0,3,0,5,6,7,8}
...
..
...
After completing the eight iteration value in the array will be
{0,0,3,0,5,0,7,0}