Even Number Counter

Easy
0/40
1 upvote

Problem statement

You are given an array arr of n integers. Your task is to count how many of these integers are even.


Detailed explanation ( Input/output format, Notes, Images )
Input Format:
The first line of input contains an integer 'n', representing the size of the array.

The second line contains 'n' space-separated integers, representing the elements of the array arr.


Output Format:
Print a single integer representing the total count of even numbers in the array.


Note:
An integer is considered even if it is perfectly divisible by 2 (i.e., number % 2 == 0).

Zero (0) is an even number.

Negative even numbers (e.g., -2, -4) should also be counted.
Sample Input 1:
6
4 7 2 9 8 3


Sample Output 1:
3


Explanation for Sample 1:
The numbers in the array are 4, 7, 2, 9, 8, and 3.
The even numbers among them are 4, 2, and 8. The total count is 3.


Sample Input 2:
5
1 3 5 7 9


Sample Output 2:
0


Explanation for Sample 2:
There are no even numbers in the given array.


Expected Time Complexity:
The expected time complexity is O(n).


Constraints:
1 <= n <= 10^5
-10^9 <= arr[i] <= 10^9
Time limit: 1 sec
Approaches (1)
Even Number Counter
Time Complexity
Space Complexity
Code Solution
(100% EXP penalty)
Even Number Counter
Full screen
Console