Removing Duplicates
In this program we try to remove all the duplicates in an given array. We do so by first searching the array and then shifting the array whenever we find a number that matches the number in concern.
/*
http://www.ProbCOMP.com
In this program we try to remove all the duplicates in an given array. We do so by first searching the array and then shifting the array
whenever we find a number that matches the number in concern.
*/
#include<stdio.h>
void main()
{
int arr[10],i,j,k;
printf("enter 10 values of the array: ");
for(i=0;i<10;i++)
scanf("%d",&arr[i]);
int size=10;
for(i=0;i<size;i++)
{
for(j=i+1;j<size;j++)
{
if(arr[i]==arr[j])
{
for(k=j+1;k<size;k++)
{
arr[k-1]=arr[k];
}
arr[k-1]=0;
size--;
j--;
}
}
}
printf("\n");
for(i=0;i<size;i++)
printf("%d ",arr[i]);
}
Download Program


