Find the XOR of first half and second half elements of an array | C # program to find the xor of the first half elements and second half elements of an array ; Function to find the xor of the first half elements and second half elements of an array ; xor of elements in FirstHalfXOR ; xor of elements in SecondHalfXOR ; Driver Code ; Function call
using System ; class GFG { static void XOROfElements ( int [ ] arr , int n ) { int FirstHalfXOR = 0 ; int SecondHalfXOR = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( i < n / 2 ) FirstHalfXOR ^= arr [ i ] ; else SecondHalfXOR ^= arr [ i ] ; } Console . Write ( FirstHalfXOR + " , " + SecondHalfXOR + " STRNEWLINE " ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { 20 , 30 , 50 , 10 , 55 , 15 , 42 } ; int N = arr . Length ; XOROfElements ( arr , N ) ; } }