Find unique no (algo ++ )

#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,ans=0,num;
cout<<“how many no. you want to insert”<<endl;
cin>>n;
for(int i=0;i<n;i++)
{
cin>>num;
num=num^ans;
}
cout<<num;
cout<<num^res;

}
why this code is not producing output

num=num^ans; so you doing XOR operation with ans =0 and again storing it to num

you should do it as ans = ans ^ num;

then print ans
Hope this helps