Given an array **arr[]** of integer elements, the task is to find the total number of sub-sets of **arr[]** in which product of the elements is even.

**Examples:**

Input:arr[] = {2, 2, 3}

Output:6

All possible sub-sets are {2}, {2}, {2, 2}, {2, 3}, {2, 3} and {2, 2, 3}

Input:arr[] = {3, 3, 3}

Output:0

**Approach:** We already know that :

- Even * Even = Even
- Odd * Even = Even
- Odd * Odd = Odd

Now, we need to count the total subsets in which at least a single even element is present in order for the product of the elements to be even.

Now, **Total number of sub-sets having at least one even element = Total possible sub-sets of n – Total sub-sets having all odd elements**

i.e. **(2 ^{n} – 1) – (2^{totalOdd} – 1)**

Below is the implementation of the above approach:

## C++

`// C++ implementation of above approach ` ` ` `#include <iostream> ` `#include<bits/stdc++.h> ` ` ` `using` `namespace` `std; ` ` ` `// Function to find total number of subsets ` `// in which product of the elements is even ` `void` `find(` `int` `a[], ` `int` `n) ` `{ ` ` ` `int` `count_odd = 0; ` ` ` ` ` `for` `(` `int` `i = 0; i < n ; i++) ` ` ` `{ ` ` ` `// counting number of odds elements ` ` ` `if` `(i % 2 != 0) ` ` ` `count_odd += 1; ` ` ` `} ` ` ` ` ` `int` `result = ` `pow` `(2, n) - 1 ; ` ` ` `result -= (` `pow` `(2, count_odd) - 1) ; ` ` ` `cout << result << endl; ` ` ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `int` `a[] = {2, 2, 3} ; ` ` ` `int` `n = ` `sizeof` `(a)/` `sizeof` `(a[0]) ; ` ` ` ` ` `// function calling ` ` ` `find(a,n); ` ` ` ` ` `return` `0; ` ` ` `// This code is contributed by ANKITRAI1; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java implementation of above approach ` ` ` `class` `GFG { ` ` ` `// Function to find total number of subsets ` `// in which product of the elements is even ` ` ` `static` `void` `find(` `int` `a[], ` `int` `n) { ` ` ` `int` `count_odd = ` `0` `; ` ` ` ` ` `for` `(` `int` `i = ` `0` `; i < n; i++) { ` ` ` `// counting number of odds elements ` ` ` `if` `(i % ` `2` `!= ` `0` `) { ` ` ` `count_odd += ` `1` `; ` ` ` `} ` ` ` `} ` ` ` ` ` `int` `result = (` `int` `) (Math.pow(` `2` `, n) - ` `1` `); ` ` ` `result -= (Math.pow(` `2` `, count_odd) - ` `1` `); ` ` ` `System.out.println(result); ` ` ` ` ` `} ` ` ` `// Driver code ` ` ` `public` `static` `void` `main(String[] args) { ` ` ` `int` `a[] = {` `2` `, ` `2` `, ` `3` `}; ` ` ` `int` `n = a.length; ` ` ` `// function calling ` ` ` `find(a, n); ` ` ` ` ` `} ` `} ` `//this code contributed by 29AJayKumar ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 implementation of above approach ` `import` `math as ma ` ` ` `# Function to find total number of subsets ` `# in which product of the elements is even ` `def` `find(a): ` ` ` `count_odd ` `=` `0` ` ` `for` `i ` `in` `a: ` ` ` ` ` `# counting number of odds elements ` ` ` `if` `(i ` `%` `2` `!` `=` `0` `): ` ` ` `count_odd` `+` `=` `1` ` ` ` ` `result ` `=` `pow` `(` `2` `, ` `len` `(a)) ` `-` `1` ` ` `result ` `=` `result ` `-` `(` `pow` `(` `2` `, count_odd) ` `-` `1` `) ` ` ` `print` `(result) ` ` ` `# Driver code ` `a ` `=` `[` `2` `, ` `2` `, ` `3` `] ` `find(a) ` |

*chevron_right*

*filter_none*

## C#

` ` `// C# implementation of above approach ` `using` `System; ` `public` `class` `GFG { ` ` ` `// Function to find total number of subsets ` `// in which product of the elements is even ` ` ` `static` `void` `find(` `int` `[]a, ` `int` `n) { ` ` ` `int` `count_odd = 0; ` ` ` ` ` `for` `(` `int` `i = 0; i < n; i++) { ` ` ` `// counting number of odds elements ` ` ` `if` `(i % 2 != 0) { ` ` ` `count_odd += 1; ` ` ` `} ` ` ` `} ` ` ` ` ` `int` `result = (` `int` `) (Math.Pow(2, n) - 1); ` ` ` `result -= (` `int` `)(Math.Pow(2, count_odd) - 1); ` ` ` `Console.Write(result); ` ` ` ` ` `} ` ` ` `// Driver code ` ` ` `public` `static` `void` `Main() { ` ` ` `int` `[]a = {2, 2, 3}; ` ` ` `int` `n = a.Length; ` ` ` `// function calling ` ` ` `find(a, n); ` ` ` ` ` `} ` `} ` `//this code contributed by 29AJayKumar ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP implementation of above approach ` ` ` `// Function to find total number of subsets ` `// in which product of the elements is even ` `function` `find(&` `$a` `, ` `$n` `) ` `{ ` ` ` `$count_odd` `= 0; ` ` ` ` ` `for` `(` `$i` `= 0; ` `$i` `< ` `$n` `; ` `$i` `++) ` ` ` `{ ` ` ` `// counting number of odds elements ` ` ` `if` `(` `$i` `% 2 != 0) ` ` ` `$count_odd` `+= 1; ` ` ` `} ` ` ` ` ` `$result` `= pow(2, ` `$n` `) - 1 ; ` ` ` `$result` `-= (pow(2, ` `$count_odd` `) - 1) ; ` ` ` `echo` `$result` `.` `"\n"` `; ` ` ` `} ` ` ` `// Driver code ` ` ` `$a` `= ` `array` `(2, 2, 3) ; ` `$n` `= sizeof(` `$a` `)/sizeof(` `$a` `[0]) ; ` ` ` `// function calling ` `find(` `$a` `,` `$n` `); ` ` ` `return` `0; ` ` ` `?> ` |

*chevron_right*

*filter_none*

**Output:**

6

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:

- Total number of Subsets of size at most K
- Partition an array of non-negative integers into two subsets such that average of both the subsets is equal
- Sum of subsets of all the subsets of an array | O(3^N)
- Sum of subsets of all the subsets of an array | O(2^N)
- Sum of subsets of all the subsets of an array | O(N)
- Divide array in two Subsets such that sum of square of sum of both subsets is maximum
- Product of all sorted subsets of size K using elements whose index divide K completely
- Total ways of choosing X men and Y women from a total of M men and W women
- Construct an Array of size N in which sum of odd elements is equal to sum of even elements
- Number of subsets with product less than k
- Total number of triplets (A, B, C) in which the points B and C are Equidistant to A
- Count subsets having distinct even numbers
- Maximum and Minimum Product Subsets
- Sum of product of all subsets formed by only divisors of N
- Product of Primes of all Subsets
- Product of values of all possible non-empty subsets of given Array
- Product of all Subsets of a set formed by first N natural numbers
- Subsets of size K with product equal to difference of two perfect squares
- Maximize count of subsets having product of smallest element and size of the subset at least X
- Maximum sum of even indexed elements obtained by right shift on an even sized subarray

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.