[Solved] Arrays with even and odd numbers [closed]


You can fill out two arrays with odd, even numbers like this

var evenArray = new int[10];
var oddArray = new int[10];

for (int i = 0, even = 0; i < evenArray.Length; i++, even += 2)
{
    evenArray[i] = even;
}

for (int i = 0, odd = 1; i < oddArray.Length; i++, odd += 2)
{
    oddArray[i] = odd;
}

Produces

evenArray = [ 0, 2, 4, 6, 8, 10, 12, 14, 16, 18 ]
oddArray = [ 1, 3, 5, 7, 9, 11, 13, 15, 17, 19 ]

2

solved Arrays with even and odd numbers [closed]