Video courses for company/skill based Preparation
Purchase mock tests for company/skill building
Python program to count numbers of even and odd elements in an array
Count number of even and odd elements in an array
In this page we are going to count number of even and odd elements in an array using python. let’s see how to find whether a number is even or odd
Any number divisible by 2 is even and which is not divisible by 2 is odd number. We can use % operator to find whether it is divisible by 2 or not. By this we can count number of even and odd elements in an array using python. See the example for better understand
- size of array- 6
- array elements- 12 34 56 89 70 35
- number of even elements- 4
- number of odd elements- 2
- 12, 34, 56, 70 are even elements
- 89, 35 are odd elements
- Input the number of elements of the array.
- Input the array elements.
- Initialize even_count = odd_count = 0.
- Traverse the array and increment odd_count if the array element is odd, else increment even_count.
- Print even_count and odd_count.
Enter array size:
Enter array elements:
Number of even elements 2 Number of odd elements 4