Count pairs with Odd XOR | C ++ program to count pairs in array whose XOR is odd ; A function will return number of pair whose XOR is odd ; To store count of odd and even numbers ; Increase even if number is even otherwise increase odd ; Return number of pairs ; Driver program to test countXorPair ( )
#include <iostream> NEW_LINE using namespace std ; int countXorPair ( int arr [ ] , int n ) { int odd = 0 , even = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] % 2 == 0 ) even ++ ; else odd ++ ; } return odd * even ; } int main ( ) { int arr [ ] = { 1 , 2 , 3 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << countXorPair ( arr , n ) ; return 0 ; }