Thread: Find the number of even numbers on even positions

1. Find the number of even numbers on even positions

Display the number of even numbers on even positions in the sequence.

Input
5
1 2 4 5 6

Output
2

2. You're not expecting us to do your assignment for you, are you? Because we won't.

3. What are you having problems with?
Just iterate through the indices 0, 2, 4, 6... and check if the number at this position is even or not (using modulo).

You need 2 variables - counter and position. If position is odd, ignore current number, otherwise check if the current number is even and increment counter.

4. Originally Posted by kmdv
What are you having problems with?
Just iterate through the indices 0, 2, 4, 6... and check if the number at this position is even or not (using modulo).

You need 2 variables - counter and position. If position is odd, ignore current number, otherwise check if the current number is even and increment counter.
its easier to input them into an array, then move through them with a double incrementing for loop
Code:
`for(int a = 0; a < array_end; a+=2)`

5. Originally Posted by bobknows
its easier to input them into an array, then move through them with a double incrementing for loop
Code:
`for(int a = 0; a < array_end; a+=2)`
I wouldn't say it's easier, he probably doesn't know how to create a dynamic array. Moreover it would needlessly consume memory.

6. true,

i guess i was only thinking of how short to get it, not how complex it would be.
i didnt think of having one variable and cin ing it multiple times either.