Tuesday, 1 October 2013

For statement find unique values

For statement find unique values

I am trying to find the unique values in the array num[], without
functions, C++ Unique values in that an array with (3,5,3,4) would only
find 3 unique values, the array comparing against itself. Size is the
elements in the array(size 4 for the above array)
for ( k=0; k<size; k++){
for (i=1;num[k]!=num[i]&&i<size; i++) { // i = 1 don't want it to
compare itself
if ( i+1 == size) {
unique++;
}
}
}
The problem I keep getting 1 or 0 unique values depending on what I do,
any suggestions in the right direction would be helpful.

No comments:

Post a Comment