# Find the number of even numbers on even positions

• 02-25-2011
teodorrupi
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
• 02-25-2011
rags_to_riches
You're not expecting us to do your assignment for you, are you? Because we won't.
• 02-25-2011
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.
• 02-26-2011
bobknows
Quote:

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)`
• 02-27-2011
kmdv
Quote:

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.
• 02-27-2011
bobknows
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.