XOR of pairwise sum of every unordered pairs in an array | C ++ implementation to find XOR of pairwise sum of every unordered pairs in an array ; Function to find XOR of pairwise sum of every unordered pairs ; Loop to choose every possible pairs in the array ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int xorOfSum ( int a [ ] , int n ) { int answer = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) answer ^= ( a [ i ] + a [ j ] ) ; } return answer ; } int main ( ) { int n = 3 ; int A [ n ] = { 1 , 2 , 3 } ; cout << xorOfSum ( A , n ) ; return 0 ; }