Can someone check, if this code is right? It should return a number, that is unique. At first a person enters a number (how many numbers will there be, and I called it n, I already entered it before) and then he enters the numbers ( for e.g n=8, so he enterns those 8 numbers). The program should calculate the biggest and not repeating number. "s" I named that unique number. For e.g n=8, enters 1 1 1 3 5 6 2 2 , and it should print 6. I appreciate your help :)
1 2 3 4 5 6 7 8 9 10 11 12 13 14
int best(int P[], int &n)
{
int s=0;
for(int i=0;i<n;i++)
{
cin>>P[i];
if(P[i] != P[i+1] )
{
if(P[i]>s)
s=P[i];
}
}
return s;
}