Check if Sum and XOR of all elements of array is equal | C ++ Implementation to Check if Sum and XOR of all Elements of Array is equal ; Function to Check if Sum and XOR of all elements of array is equal ; Sum and XOR of all elements ; Checking Sum and XOR to be equal ; Driver Function ; Check Sum and XOR is equal
#include <iostream> NEW_LINE using namespace std ; int equal_xor_sum ( int arr [ ] , int n ) { int Sum = 0 ; int Xor = 0 ; for ( int i = 0 ; i < n ; i ++ ) { Sum = Sum + arr [ i ] ; Xor = Xor ^ arr [ i ] ; } if ( Sum == Xor ) cout << " YES " ; else cout << " NO " ; return 0 ; } int main ( ) { int arr [ ] = { 6 , 3 , 7 , 10 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; equal_xor_sum ( arr , n ) ; return 0 ; }