Find XOR sum of Bitwise AND of all pairs from given two Arrays | C ++ algorithm for the above approach ; Function to calculate the XOR sum of all ANDS of all pairs on A [ ] and B [ ] ; variable to store anshu ; when there has been no AND of pairs before this ; Driver code ; Input ; Function call
#include <bits/stdc++.h> NEW_LINE using namespace std ; int XorSum ( int A [ ] , int B [ ] , int N , int M ) { int ans = -1 ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) { if ( ans == -1 ) ans = ( A [ i ] & B [ j ] ) ; else ans ^= ( A [ i ] & B [ j ] ) ; } } return ans ; } int main ( ) { int A [ ] = { 3 , 5 } ; int B [ ] = { 2 , 3 } ; int N = sizeof ( A ) / sizeof ( A [ 0 ] ) ; int M = sizeof ( B ) / sizeof ( B [ 0 ] ) ; cout << XorSum ( A , B , N , M ) << endl ; }