Header Ads Widget

Write a program to delete duplicate element in a list of 10 elements & display it on screen.

 Code:-

#include<stdio.h>
int main()
{
int a[10],b[10],i,j,k=0;
printf("Enter 10 element of the list\n");
for(i=0;i<10;i++)
scanf("%d",&a[i]);
// logic for deleting duplicates
for(i=0;i<10;i++)
{
for(j=0;j<k;j++)
{
if(b[j]==a[i])
break;
}
if(j==k)
{
b[k]=a[i];
k++;
}
}
printf("The ans is: ");
for(i=0;i<k;i++)
printf("%d ",b[i]);
return 0;
}

Output:-

Enter 10 element of the list
12 3 4 12 5 6 7 6 8 10
The ans is : 12 3 4 5 6 7 8 10




Post a Comment

0 Comments