XOR of Sum of every possible pair of an array | C ++ program to find XOR of sum of every possible pairs in an array ; Function to find XOR of sum of all pairs ; Calculate xor of all the elements ; Return twice of xor value ; Drivers code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int findXor ( int arr [ ] , int n ) { int xoR = 0 ; for ( int i = 0 ; i < n ; i ++ ) { xoR = xoR ^ arr [ i ] ; } return xoR * 2 ; } int main ( ) { int arr [ 3 ] = { 1 , 5 , 6 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << findXor ( arr , n ) ; return 0 ; }