You exceeded the bounds of the array definition, what data you fetch or corrupt when you do that is up to the "memory alignment gods". Fix the program as suggested so that you do not exceed the array boundaries and you will stop getting wierd output.
You told me to fix the size. How to change because its been initialized. Mr crow told to increment later in the loop. But its should be there in the while part itself. If so how to rectify by changing the array size.
As long as you insist that you don't need any code modifications, you will get nowhere with changing the array dimensions.
You are computing and filling in array entries 1 through 5
You are printing out array entries 0 through 4
That is *bad code*, changing array dimensions will not affect this basic flaw.
David Crow has given you two excellent hints (nobody is going to write the program for you). I gave you hints on the fundamental problem. Now it is your turn to demonstrate that you have read, understood, and found the problem yourself. David and I have already passed this course.
You got that answer because your program is logically flawed because of the way you increment the counter i in the first loop as you've been repeatedly told. Unless you change that, you'll never get the right answer. Most people use for loops in instances like yours.
You measure democracy by the freedom it gives its dissidents, not the freedom it gives its assimilated conformists.