1. ## Can you give me your tip plz :)

How i can find duplicated numbers in an array.

#1.I have a rand() function that assign numbers in an array.

#2.I want to find if there are at least 2 duplicated numbers,
unfortunately i dont know how ... can you give me your suggestions plz...

2. Originally Posted by dionys
How i can find duplicated numbers in an array.

#1.I have a rand() function that assign numbers in an array.

#2.I want to find if there are at least 2 duplicated numbers,
unfortunately i dont know how ... can you give me your suggestions plz...
Just check each number in the array against the others...so it'd be like:

Code:
```i = 1;
t = 20;

while i < 20
if numbers_in_array[i] = numbers_in_array[i++]
do something```
I know this doesn't work, and there is flaws in it, but it's a general idea.

3. >can you give me your suggestions plz...
Use a frequency table would be my first suggestion:
Code:
```#include <stdio.h>

int main ( void )
{
int a[] = {0,1,2,3,4,5,4,6,7,3,8,9};
int freq[10] = {0};
int i;

for ( i = 0; i < 12; i++ )
freq[ a[i] ]++;
for ( i = 0; i < 10; i++ )
printf ( "%d: %d\n", i, freq[i] );

return 0;
}```

4. 2 nested loops, try comparing each array element with every other array element. give it a shot, post code, and the highly secret, arcane knowledge required to do this (which cannot be found anywhere else on the internet!) will be passed on to you, young padawan

edit: o shi

5. Prelude's idea of using a frequency table is definitely more efficient than checking every element in an array in most cases, although if you're choosing 10 random numbers from a group of 400 000, the check every element method works much better (in terms of memory efficiency).

6. >although if you're choosing 10 random numbers from a group of 400 000
Of course, since the OP gave no specific numbers, we can't make that assumption. So without more detail, the simpler method is preferred. If the range of numbers is too much for a table, then a binary search tree would be much better than a table for space usage, without much loss in performance. However, the nested loop option will likely be more efficient if the arrays are sure to be very small. The choice of solution depends on the data.

7. Originally Posted by Prelude
>although if you're choosing 10 random numbers from a group of 400 000
Of course, since the OP gave no specific numbers, we can't make that assumption. So without more detail, the simpler method is preferred.
Or the guaranteed method is preferred, as a freq table may be too large and unwieldly...

Originally Posted by Prelude
The choice of solution depends on the data.
So true