Here i made some modifications to ur prm.
1.In 1st for loop index value should be decremented,before checking the condition.Bcoz u r doing post increment.
2.In 2nd for loop im using index value...