Find the count of even odd pairs in a given Array | C ++ program to count the pairs in array of the form ( even , odd ) ; Function to count the pairs in array of the form ( even , odd ) ; variable to store count of such pairs ; Iterate through all pairs ; Increment count if condition is satisfied ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int findCount ( int arr [ ] , int n ) { int res = 0 ; for ( int i = 0 ; i < n - 1 ; i ++ ) for ( int j = i + 1 ; j < n ; j ++ ) if ( ( arr [ i ] % 2 == 0 ) && ( arr [ j ] % 2 == 1 ) ) { res ++ ; } return res ; } int main ( ) { int a [ ] = { 5 , 4 , 1 , 2 , 3 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; cout << findCount ( a , n ) ; return 0 ; }