Replace every element of the array with BitWise XOR of all other | C # program to Replace every element by the bitwise xor of all other elements ; Function to replace the elements ; Calculate the xor of all the elements ; Replace every element by the xor of all other elements ; Driver code ; Print the modified array .
using System ; public class GFG { static void ReplaceElements ( int [ ] arr , int n ) { int X = 0 ; for ( int i = 0 ; i < n ; ++ i ) { X ^= arr [ i ] ; } for ( int i = 0 ; i < n ; ++ i ) { arr [ i ] = X ^ arr [ i ] ; } } static public void Main ( ) { int [ ] arr = { 2 , 3 , 3 , 5 , 5 } ; int n = arr . Length ; ReplaceElements ( arr , n ) ; for ( int i = 0 ; i < n ; ++ i ) { Console . Write ( arr [ i ] + " ▁ " ) ; } } }