I need help for the following code. I have an array, which skip every 3
elements in the array. The code works with indexes of the array.
The parts with ----- have to fill with some code.
Can anyone help me? I have the following code:
I tried this.
static int[] SkipEvery(int[] numbers,int skip)
{
int[] skipped = new int[numbers.Length];
for (int i = 0; i < numbers.Length; i++)
{
if ((numbers[i]) % (skip + 1) == 0)
{
skipped[i] = numbers[i];
}
else
{
skipped[i] = numbers[i];
}
}
return skipped;
}
public static void Main(string[] args)
{
int[] numbers = new int[] { 7, 2, 24, 69, 101, 42, 84, 100, 72 };
numbers = SkipEvery(numbers, 3);
}
The output must be
[0]7 [1]2 [2]24 [3]-1 [4]101 [5]42 [6]84 [7]-1 [8]72
But with this code the output is
[0]7 [1]2 [2]24 [3]69 [4]101 [5]42 [6]84 [7]100 [8]72