# Thread: eliminating dup values in array

1. ## eliminating dup values in array

I need to write a program that reads in 20 numbers between 10 and 100 using a single-subscripted array and then as each number is read, print it only if it's not a duplicate of a number already read.

I can read in the numbers and initialize the element values in the array, but have no idea how to eliminate the dups when printing.

Our teacher said we could search the array and eliminate the dup and shift the next element up but she didn't tell us how to do that. I'm lost. We have learned binary search trees yet, just linear search and binary search.

I think I have to use a bunch of nested for loops, but can't get it.

2. The easiest way is this:
Code:
```int array[20] ={0};
int temp,x,y;
for( x = 0; x < 20; x++ )
{
prompt for number %d, x
temp = read a number from user
for( y = 0; y < x; y++ )
if temp == array[y]
dupe = true
if dupe != true
array[x] = temp
/* else ignore it */
}```
Now just loop through the list and print any non-zero value when you're done.

Quzah.
}

3. Just read each number and then check it against the other numbers in the array. There are plenty of ways to do this, here is one of them:
Code:
```static int
checkDup ( const int *a, const int val )
{
int x, count = 0;
for ( x = 0; x < VAL_SIZE; x++ )
if ( a[x] == val ) count++;
return ( count > 1 ) ? 1 : 0;
}```
Call checkDup for every number that you read and if it returns 1, don't print it.

-Prelude