It’s hard for me to check what your loops are doing.
Instead of making it complex, you could have checked whether number is even or not at the time of input and counted the number of even numbers.
The tricky case here is if k=0 and take the elements as 2,4,6,8.
And check whether your code gives correct output or not , if not figure out that case.
Hope this helps you and keep coding.