Find the two non-repeating elements in an array of repeating elements/ Unique Numbers 2
#include <iostream>
using namespace std;
int main()
{
int n;
cout<<"enter the size of the array:"<<endl;
cin>>n;
int arr[n];
cout<<"enter the elements of the array:"<<endl;
for(int i=0;i<n;i++)
{
cin>>arr[i];
}
int res=0;
int x=0;
int y=0;
int setbit;
for(int i=0;i<n;i++)
{
res=res^arr[i];
}
setbit=res&(~(res)+1);
for(int i=0;i<n;i++)
{
if(arr[i]&setbit) //xor the first set
{
x=x^arr[i];
}
else //xor the second set
{
y=y^arr[i];
}
}
cout<<x<<" "<<y<<endl;
return 0;
}