posted 16 years ago
Deepa,
Have you tried stepping through the code yet?
The problem is this:
arr[i] = 0;
The way this for next works is for each iteration "i" will BE the next value in the array. Not the index of the next item in the array.
So stepping through it:
Iteration 1:
i = 1
set arr[1] = 0
arr = 1,0,3,4
Iteration 2:
i = 0
set arr[0] = 0
arr = 0,0,3,4
Iteration 3:
i = 3
set arr[3] = 0
arr = 0,0,3,0
Then you print them correctly giving you 0 0 3 0
:-)