Saturday, May 21, 2011

C program to remove duplicates from an array

/*Read elements into an array. Write a Program to find duplicate
elements in the array and display the resultant array by removing
the duplicates.*/


int main()
{
int a[100],i,j,k,b,t=0;


printf("\nEnter the size of 1 dimensional array");
scanf("%d",&b);
printf("\nEnter the array");
for(i=0;i scanf("%d",&a[i]);
for(i=0;i {
for(j=i+1;j {
if(a[i]==a[j])
{
t++;
for(k=j;k a[k]=a[k+1];

}
}
}
for(i=0;i<=b-t;i++)
printf("\n%d",a[i]);
system("pause");
return 0;
}

No comments:

Post a Comment