XOR of every element of an Array with a given number K | C # program to find XOR of every element of an array with a given number K ; Function to construct new array ; Traverse the array and compute XOR with K ; Print new array ; Driver code
using System ; class GFG { static void constructXORArray ( int [ ] A , int n , int K ) { int [ ] B = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) B [ i ] = A [ i ] ^ K ; for ( int i = 0 ; i < n ; i ++ ) Console . Write ( B [ i ] + " ▁ " ) ; Console . WriteLine ( ) ; } public static void Main ( String [ ] args ) { int [ ] A = { 2 , 4 , 1 , 3 , 5 } ; int K = 5 ; int n = A . Length ; constructXORArray ( A , n , K ) ; int [ ] B = { 4 , 75 , 45 , 42 } ; K = 2 ; n = B . Length ; constructXORArray ( B , n , K ) ; } }