Count pairs with Bitwise XOR as EVEN number | Function to count number of even pairs ; find all pairs ; return number of even pair ; Driver Code ; calling function findEvenPair and print number of even pair
< ? php function findEvenPair ( $ A , $ N ) { $ count = 0 ; for ( $ i = 0 ; $ i < $ N ; $ i ++ ) { if ( $ A [ $ i ] % 2 != 0 ) $ count ++ ; } $ totalPairs = ( $ N * ( $ N - 1 ) / 2 ) ; $ oddEvenPairs = $ count * ( $ N - $ count ) ; return $ totalPairs - $ oddEvenPairs ; } $ a = array ( 5 , 4 , 7 , 2 , 1 ) ; $ n = sizeof ( $ a ) ; echo findEvenPair ( $ a , $ n ) . " STRNEWLINE " ; ? >