Number whose XOR sum with given array is a given number k | CPP Program to find the number whose XOR sum with given array is equal to a given number k ; This function returns the number to be inserted in the given array ; initialise the answer with k ; ans ^= A [ i ] ; XOR of all elements in the array ; Driver Code to test above function
#include <bits/stdc++.h> NEW_LINE using namespace std ; int findEletobeInserted ( int A [ ] , int n , int k ) { int ans = k ; for ( int i = 0 ; i < n ; i ++ ) return ans ; } int main ( ) { int A [ ] = { 1 , 2 , 3 , 4 , 5 } ; int n = sizeof ( A ) / sizeof ( A [ 0 ] ) ; int k = 10 ; cout << findEletobeInserted ( A , n , k ) << " ▁ has ▁ to ▁ be ▁ inserted " " ▁ in ▁ the ▁ given ▁ array ▁ to ▁ make ▁ xor ▁ sum ▁ of ▁ " << k << endl ; return 0 ; }