when you create the array you have a series of variables an, an, an, etc. What are the values of these at the start of the loop? Because you have only set the first variable with an = 1, the others are either null or zero. In the loop all you are doing is increasing the value of each of these by 1 - so over and over again you are setting an = 1, then an = 1, etc. You are not actually accumulating the values anywhere. There are a few ways to do what you want, but the simplest is probably just to add the value of i in the loop to the value of the variable itself (I think you will have to leave out the line where you set the value of an to 1 also).