-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmex.cpp
More file actions
38 lines (29 loc) · 652 Bytes
/
Copy pathmex.cpp
File metadata and controls
38 lines (29 loc) · 652 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// C++ program to find the XOR of
// all elements in the array
#include <bits/stdc++.h>
using namespace std;
// Function to find the XOR of
// all elements in the array
int xorOfArray(int arr[], int n)
{
// Resultant variable
int xor_arr = 0;
// Iterating through every element in
// the array
for (int i = 0; i < n; i++)
{
// Find XOR with the result
xor_arr = xor_arr ^ arr[i];
}
// Return the XOR
return xor_arr;
}
// Driver Code
int main()
{
int arr[] = {0,1,2,3};
int n = sizeof(arr) / sizeof(arr[0]);
// Function call
cout << xorOfArray(arr, n) << endl;
return 0;
}