text: Find number of pairs in an array such that their XOR is 0 | C # program to find number of pairs in an array such that their XOR is 0 ; Function to calculate the answer ; Finding the maximum of the array ; Creating frequency array With initial value 0 ; Traversing through the array ; Counting frequency ; Traversing through the frequency array ; Calculating answer ; Driver Code ; Function calling
code: using System ; using System . Linq ; class GFG { static int calculate ( int [ ] a , int n ) { int maximum = a . Max ( ) ; int [ ] frequency = new int [ maximum + 1 ] ; for ( int i = 0 ; i < n ; i ++ ) { frequency [ a [ i ] ] += 1 ; } int answer = 0 ; for ( int i = 0 ; i < ( maximum ) + 1 ; i ++ ) { answer = answer + frequency [ i ] * ( frequency [ i ] - 1 ) ; } return answer / 2 ; } public static void Main ( String [ ] args ) { int [ ] a = { 1 , 2 , 1 , 2 , 4 } ; int n = a . Length ; Console . WriteLine ( calculate ( a , n ) ) ; } }