Duplicate element deletion form an array

Leave a Comment
#include<conio.h>
#include<stdio.h>
int main()
{
int a[100],n,t,i,j;
printf("Enter the max limit:");
scanf("%d",&n);
for(i=0;i<n;i++)

{
printf("\nEnter the number:");
scanf("%d",&a[i]);
}
printf("\nThe the array element will be sorted in increasing order!!!\n\n");
for(i=0;i<n-1;i++){
for(j=i+1;j<n;j++){
if(a[i]>a[j])
{t=a[i];
a[i]=a[j];
a[j]=t;
}
}
}
for(i=0;i<n-1;i++){
for(j=i+1;j<n;j++){
if(a[i]==a[j])
{ t=j;
while(t{
a[t]=a[t+1];
t++;
}
n--;
}
}
}
printf("\nThe array after deleting the duplicate elements is\n\n");
for(i=0;i<n;i++){
printf("%d\t",a[i]);
}
getche();
return 0;
}

0 comments: