Given an array **arr[]** containing **n** numbers. The problem is to check whether the product of the given **n** numbers is even or odd.

**Examples:**

Input : arr[] = {2, 4, 3, 5} Output : Even Product = 2 * 4 * 3 * 5 = 120 Input : arr[] = {3, 9, 7, 1} Output : Odd

A **simple solution** is to first find the product, then check if the product is even or odd. This solution causes overflow for large arrays.

A **better solution** is based on following mathematical calculation facts:

- Product of two even numbers is even.
- Product of two odd numbers is odd.
- Product of one even and one odd number is even.

Based on the above facts, if a single even number occurs then the entire product of **n** numbers will be even else odd.

## C++

`// C++ implementation to check whether product of ` `// 'n' numbers is even or odd ` `#include <bits/stdc++.h> ` ` ` `using` `namespace` `std; ` ` ` `// function to check whether product of ` `// 'n' numbers is even or odd ` `bool` `isProductEven(` `int` `arr[], ` `int` `n) ` `{ ` ` ` `for` `(` `int` `i = 0; i < n; i++) ` ` ` ` ` `// if a single even number is found, then ` ` ` `// final product will be an even number ` ` ` `if` `((arr[i] & 1) == 0) ` ` ` `return` `true` `; ` ` ` ` ` `// product is an odd number ` ` ` `return` `false` `; ` `} ` ` ` `// Driver program to test above ` `int` `main() ` `{ ` ` ` `int` `arr[] = { 2, 4, 3, 5 }; ` ` ` `int` `n = ` `sizeof` `(arr) / ` `sizeof` `(arr[0]); ` ` ` `if` `(isProductEven(arr, n)) ` ` ` `cout << ` `"Even"` `; ` ` ` `else` ` ` `cout << ` `"Odd"` `; ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java implementation to check whether product of ` `// 'n' numbers is even or odd ` ` ` `public` `class` `GFG { ` ` ` ` ` `// function to check whether product of ` ` ` `// 'n' numbers is even or odd ` ` ` `static` `boolean` `isProductEven(` `int` `arr[], ` `int` `n) ` ` ` `{ ` ` ` `for` `(` `int` `i = ` `0` `; i < n; i++) ` ` ` ` ` `// if a single even number is found, then ` ` ` `// final product will be an even number ` ` ` `if` `((arr[i] & ` `1` `) == ` `0` `) ` ` ` `return` `true` `; ` ` ` ` ` `// product is an odd number ` ` ` `return` `false` `; ` ` ` `} ` ` ` ` ` ` ` `// Driver code ` ` ` `public` `static` `void` `main(String args[]) ` ` ` `{ ` ` ` `int` `arr[] = { ` `2` `, ` `4` `, ` `3` `, ` `5` `}; ` ` ` `int` `n = arr.length ; ` ` ` `if` `(isProductEven(arr, n)) ` ` ` `System.out.println(` `"Even"` `); ` ` ` `else` ` ` `System.out.println(` `"Odd"` `) ; ` ` ` `} ` ` ` `// This Code is contributed by ANKITRAI1 ` `} ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 implementation to ` `# check whether product of 'n' ` `# numbers is even or odd ` ` ` `# function to check whether ` `# product of 'n' numbers is ` `# even or odd ` `def` `isProductEven(arr, n): ` ` ` ` ` `for` `i ` `in` `range` `(` `0` `, n): ` ` ` ` ` `# if a single even number is ` ` ` `# found, then final product ` ` ` `# will be an even number ` ` ` `if` `((arr[i] & ` `1` `) ` `=` `=` `0` `): ` ` ` `return` `True` ` ` ` ` `# product is an odd number ` ` ` `return` `False` ` ` `# Driver Code ` `arr ` `=` `[ ` `2` `, ` `4` `, ` `3` `, ` `5` `] ` `n ` `=` `len` `(arr) ` `if` `(isProductEven(arr, n)): ` ` ` `print` `(` `"Even"` `) ` `else` `: ` ` ` `print` `(` `"Odd"` `) ` ` ` `# This code is contributed ` `# by ihritik ` |

*chevron_right*

*filter_none*

## C#

`// C# implementation to check ` `// whether product of 'n' ` `// numbers is even or odd ` `using` `System; ` ` ` `class` `GFG ` `{ ` ` ` `// function to check whether ` `// product of 'n' numbers ` `// is even or odd ` `static` `bool` `isProductEven(` `int` `[]arr, ` `int` `n) ` `{ ` ` ` `for` `(` `int` `i = 0; i < n; i++) ` ` ` ` ` `// if a single even number is ` ` ` `// found, then final product ` ` ` `// will be an even number ` ` ` `if` `((arr[i] & 1) == 0) ` ` ` `return` `true` `; ` ` ` ` ` `// product is an odd number ` ` ` `return` `false` `; ` `} ` ` ` `// Driver code ` `public` `static` `void` `Main() ` `{ ` ` ` `int` `[]arr = { 2, 4, 3, 5 }; ` ` ` `int` `n = arr.Length; ` ` ` `if` `(isProductEven(arr, n)) ` ` ` `Console.WriteLine(` `"Even"` `); ` ` ` `else` ` ` `Console.WriteLine(` `"Odd"` `) ; ` `} ` `} ` ` ` `// This code is contributed by ihritik ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP implementation to check ` `// whether product of 'n' numbers ` `// is even or odd ` ` ` `// function to check whether ` `// product of 'n' numbers is ` `// even or odd ` `function` `isProductEven(` `$arr` `, ` `$n` `) ` `{ ` ` ` `for` `(` `$i` `= 0; ` `$i` `< ` `$n` `; ` `$i` `++) ` ` ` ` ` `// if a single even number is ` ` ` `// found, then final product ` ` ` `// will be an even number ` ` ` `if` `((` `$arr` `[` `$i` `] & 1) == 0) ` ` ` `return` `true; ` ` ` ` ` `// product is an odd number ` ` ` `return` `false; ` `} ` ` ` `// Driver code ` `$arr` `= ` `array` `( 2, 4, 3, 5 ); ` `$n` `= sizeof(` `$arr` `); ` `if` `(isProductEven(` `$arr` `, ` `$n` `)) ` ` ` `echo` `"Even"` `; ` `else` ` ` `echo` `"Odd"` `; ` ` ` `// This code is contributed by ihritik ` `?> ` |

*chevron_right*

*filter_none*

**Output:**

Even

**Time Complexity:** O(n).

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:

- Check if N can be expressed as product of 3 distinct numbers
- Check if all sub-numbers have distinct Digit product
- Check if product of first N natural numbers is divisible by their sum
- Check if each element of the given array is the product of exactly K prime numbers
- Check if product of array containing prime numbers is a perfect square
- Check whether a number can be expressed as a product of single digit numbers
- Numbers less than N which are product of exactly two distinct prime numbers
- Absolute difference between the Product of Non-Prime numbers and Prime numbers of an Array
- Find two numbers with sum and product both same as N
- Print a pair of numbers with the given Sum and Product
- Sort the numbers according to their product of digits
- Find the Product of first N Prime Numbers
- Product of all the Composite Numbers in an array
- Find if n can be written as product of k numbers
- Number of digits in the product of two numbers
- First digit in product of an array of numbers
- Check whether product of integers from a to b is positive , negative or zero
- Check whether a number can be represented by the product of two squares
- Check if the product of every contiguous subsequence is different or not in a number
- Largest palindrome which is product of two N-digit numbers : Set 2

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.