Given an array **arr[]** of integers of size **N**, the task is to find the number elements of the array having even and odd length.

**Examples:**

Input:arr[] = {14, 735, 3333, 223222}

Output:Number of even length elements = 3

Number of odd length elements = 1

Input:arr[] = {1121, 322, 32, 14783, 44}

Output:Number of even length elements = 3

Number of odd length elements = 2

**Approach:** To calculate the number of digits having even length or odd length, convert each number into a string. Then check if the length is odd or even. Finally, print the count of numbers having even length and odd length separately.

Below is the implementation of the above approach:

## CPP

`// C++ program to find the count ` `// number of even and odd ` `// length elements in an Array ` ` ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Function to find the number elements of ` `// the array having even length and odd. ` `void` `EvenOddLength(` `int` `arr[], ` `int` `n) ` `{ ` ` ` `// Store numbers with even length ` ` ` `int` `even = 0; ` ` ` ` ` `for` `(` `int` `i = 0; i < n; i++) { ` ` ` ` ` `// Conversion of integer to string ` ` ` `string x = to_string(arr[i]); ` ` ` ` ` `if` `(x.length() % 2 == 0) ` ` ` `even++; ` ` ` `} ` ` ` ` ` `cout << ` `"Number of even "` ` ` `<< ` `"length elements = "` ` ` `<< even << endl; ` ` ` `cout << ` `"Number of odd "` ` ` `<< ` `"length elements = "` ` ` `<< n - even << endl; ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `int` `arr[] = { 12, 44, 213, 232, 3433 }; ` ` ` `int` `n = ` `sizeof` `(arr) / ` `sizeof` `(arr[0]); ` ` ` ` ` `// Function call ` ` ` `EvenOddLength(arr, n); ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java program to find the count ` `// number of even and odd ` `// length elements in an Array ` `import` `java.util.*; ` `class` `GFG{ ` ` ` `// Function to find the number elements of ` `// the array having even length and odd. ` ` ` `static` `void` `EvenOddLength(` `int` `arr[], ` `int` `n) ` ` ` `{ ` ` ` `// Store numbers with even length ` ` ` `int` `even = ` `0` `; ` ` ` ` ` `for` `(` `int` `i = ` `0` `; i < n; i++) { ` ` ` ` ` `// Conversion of integer to string ` ` ` `String x = Integer.toString(arr[i]); ` ` ` ` ` `if` `(x.length() % ` `2` `== ` `0` `) ` ` ` `even++; ` ` ` `} ` ` ` ` ` `System.out.println(` `"Number of even length elements = "` `+even); ` ` ` `System.out.println(` `"Number of odd length elements = "` `+(n - even)); ` ` ` `} ` ` ` ` ` `// Driver code ` ` ` `public` `static` `void` `main(String args[]) ` ` ` `{ ` ` ` `int` `arr[] = { ` `12` `, ` `44` `, ` `213` `, ` `232` `, ` `3433` `}; ` ` ` `int` `n = arr.length; ` ` ` ` ` `// Function call ` ` ` `EvenOddLength(arr, n); ` ` ` ` ` `} ` `} ` ` ` `// This code is contributed by AbhiThakur ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 program to find the count ` `# number of even and odd ` `# length elements in an Array ` ` ` `# Function to find the number elements of ` `# the array having even length and odd. ` `def` `EvenOddLength(arr, n): ` ` ` ` ` `# Store numbers with even length ` ` ` `even ` `=` `0` ` ` ` ` `for` `i ` `in` `range` `(n): ` ` ` ` ` `# Conversion of integer to string ` ` ` `x ` `=` `str` `(arr[i]) ` ` ` ` ` `if` `(` `len` `(x) ` `%` `2` `=` `=` `0` `): ` ` ` `even ` `+` `=` `1` ` ` ` ` `print` `( ` `"Number of even length elements = "` `, even) ` ` ` `print` `( ` `"Number of odd length elements = "` `, n ` `-` `even) ` ` ` `# Driver code ` `if` `__name__ ` `=` `=` `'__main__'` `: ` ` ` `arr` `=` `[` `12` `, ` `44` `, ` `213` `, ` `232` `, ` `3433` `] ` ` ` `n ` `=` `len` `(arr) ` ` ` ` ` `# Function call ` ` ` `EvenOddLength(arr, n) ` ` ` `# This code is contributed by mohit kumar 29 ` |

*chevron_right*

*filter_none*

## C#

`// C# program to find the count ` `// number of even and odd ` `// length elements in an Array ` `using` `System; ` ` ` `class` `GFG{ ` ` ` `// Function to find the number elements of ` `// the array having even length and odd. ` ` ` `static` `void` `EvenOddLength(` `int` `[]arr, ` `int` `n) ` ` ` `{ ` ` ` `// Store numbers with even length ` ` ` `int` `even = 0; ` ` ` ` ` `for` `(` `int` `i = 0; i < n; i++) { ` ` ` ` ` `// Conversion of integer to string ` ` ` `String x = arr[i].ToString(); ` ` ` ` ` `if` `(x.Length % 2 == 0) ` ` ` `even++; ` ` ` `} ` ` ` ` ` `Console.WriteLine(` `"Number of even length elements = "` `+even); ` ` ` `Console.WriteLine(` `"Number of odd length elements = "` `+(n - even)); ` ` ` `} ` ` ` ` ` `// Driver code ` ` ` `public` `static` `void` `Main(String []args) ` ` ` `{ ` ` ` `int` `[]arr = { 12, 44, 213, 232, 3433 }; ` ` ` `int` `n = arr.Length; ` ` ` ` ` `// Function call ` ` ` `EvenOddLength(arr, n); ` ` ` ` ` `} ` `} ` ` ` `// This code is contributed by sapnasingh4991 ` |

*chevron_right*

*filter_none*

**Output:**

Number of even length elements = 3 Number of odd length elements = 2

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the **DSA Self Paced Course** at a student-friendly price and become industry ready.

## Recommended Posts:

- Even numbers at even index and odd numbers at odd index
- Length of longest Subarray with equal number of odd and even elements
- Count number of even and odd elements in an array
- Rearrange array such that even index elements are smaller and odd index elements are greater
- Increment odd positioned elements by 1 and decrement even positioned elements by 1 in an Array
- Find Kth element in an array containing odd elements first and then even elements
- Split an Array to maximize subarrays having equal count of odd and even elements for a cost not exceeding K
- Count of even and odd set bit Array elements after XOR with K for Q queries
- Construct an Array of size N in which sum of odd elements is equal to sum of even elements
- Replace the odd positioned elements with their cubes and even positioned elements with their squares
- Count subarrays with same even and odd elements
- Count of odd and even parity elements in subarray using MO's algorithm
- Query to count odd and even parity elements in subarray after XOR with K
- Count subarrays having sum of elements at even and odd positions equal
- Generate an Array in which count of even and odd sum sub-arrays are E and O respectively
- Rearrange array such that all even-indexed elements in the Array is even
- Program to print Sum of even and odd elements in an array
- Program to print product of even and odd indexed elements in an Array
- Absolute Difference of even and odd indexed elements in an Array
- Modify given array to make sum of odd and even indexed elements same

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.