Right Click to Search

Wednesday, August 25, 2024

To delete duplicate elements in an array


Program : To delete duplicate elements in an array
#include<stdio.h>
#include<conio.h>
main()
{
int a[20],i,j,k,n;
clrscr();
printf("\nEnter array size : ");
scanf("%d",&n);
printf("\nAccept Numbers : ",n);
for(i=0;i<n;i++)
 scanf("%d",&a[i]);
clrscr();
printf("\nOriginal array is : ");
for(i=0;i<n;i++)
 printf(" %d",a[i]);
printf("\nUpdated array is  : ");
for(i=0;i<n;i++)
{
   for(j=i+1;j<n;)
   {
      if(a[j]==a[i])
      {
         for(k=j;k<n;k++)
             a[k]=a[k+1];
          n--;
      }
      else
         j++;
   }
}
for(i=0;i<n;i++)
    printf("%d ",a[i]);
getch();
}

Output :
Enter array size : 5
Accept Numbers : 1 2 2 3 4
Original array is : 1 2 2 3 4
Updated array is  : 1 2 3 4

Tags / Keywords : | ,

Stumble
Delicious
Technorati
Twitter
Facebook

0 Comments:

Post a Comment

Your Feedback :This is Growing Site and Your Feedback is important for Us to improve the Site performance & Quality of Content.Feel Free to contact and Please Provide Name & Contact Email

 

Learn C Programming Copyright © 2010 LKart Theme is Designed by Lasantha, Free Blogger Templates