Hello,
I am trying to understand the result from this code, Can anyone explain me in plain math what it is doing.
int[] array = new int[7];
int i, k;
array[0] = 1;
for ( k = 1; k < 7; k++)
{
array[k] = array[k-1] +2;
}
for(i = 0; i < 7; i++)
{
Console.WriteLine(array[i]);
}
The result is 1, 3 , 5, 7, 9, 11, 13.
If array[0] = 1, i assume first number in result is 1 than the loop begins at 1 so 1-1 +2 = 2? But at loop k= 2, 2 -1 +2 = 3? Than i will get a 4. But thats not the result. Its 5.
Thank you