Unique number II section

void unique_no(int n){
int no,res,pos=0,ar[n];
for(int i=0;i<n;i++){
cin>>no;
ar[i] = no;
res = res^no;
}
int temp = res;
while((temp&1)!=1){
pos++;
temp = temp>>1;
}
int a=0,b=0;
int mask = 1<<pos;
for(int i=0;i<n;i++){
if((ar[i]&mask)>0) {
a = a ^ ar[i];
}
}
b = a^res;

cout<<min(a,b)<<" "<<max(a,b);

}

int main(){
int n = 5;
unique_no(5);

// cout<<c;

}

this is the code that I have written and I gave the input as 1,2,4,3,2
so I want the output as 1,3,4
but it is giving the output as 3,5 what is the reason and how to get the desired output

@Somith
this algorithm is only valid when we have only two elements in array that are occuring once and reamining elements are occuring twice.

here ur input is not correct. u have given 3 elements that are occuring only once.