how can i find out duplcate numbers in an array?
how can i find out duplcate numbers in an array?
Put the array elements in a set.
i want one clarification from you
- it is normal array program or
- it is in collection frame work
algorithm:
- create an array, which contains an elements (a[])
- create another array, which is used to assign values to that array (b[])
- now u will take loop and compare two array (if a[]==b[])
- now u will print that values
please try like this, if there is any problem i will give the program for you ok
int arr[10],arrDupEle[10];
int i,j,k;
printf("Enter 10 ele :");//consider array of 10 ele
for (i=0;i<10;i++)
scanf("%d",&arr[i]);
k=0;
for (i=0;i<10;i++)
{
for (j=0;j<10;j++)
{
if (i!=j)
{
if (arr[i]==arr[j])
{
arrDupEle[k++]=arr[i];
}
}
}
}
for (i=0;i<k;i++)/////or try i<k-1
printf("%d\t",arrDupEle[i]);
try this out...........