//To Eliminate Duplicate Elements Of An Array.
#include<stdio.h>
#include<conio.h>
void main()
{
int ar[50];
int i,j,k,lim;
clrscr();
printf("\nEnter the limit of the array :");
scanf("%d",&lim);
printf("\nEnter the elements of Array :");
for(i=0;i<lim;i++)
scanf("%d",&ar[i]);
printf("\nThe Array before deletion is :\n");
for(i=0;i<lim;i++)
{
printf("%d",ar[i]);
printf("\t");
}
for(i=0;i<lim;i++)
{
for(j=i+1;j<lim;j++)
{
if(ar[i]==ar[j])
{
for(k=j;k<lim-1;k++)
{
ar[k]= ar[k+1];
}
lim=lim-1;
j--;
}
}
}
printf("\nThe array after deletion is:\n\n");
for(i=0;i<lim;i++)
{
printf("%d",ar[i]);
printf("\t");
}
getch();
}
0 comments:
Post a Comment