Remove the duplicate elements in an integer array | User given | C-Program

Remove the duplicate elements from an integer array:

Code :- 

#include<stdio.h>

void main()

{
  int var[20],n;

  printf("Enter the number of elements :- ");

  scanf("%d",&n);

  printf("Enter the %d array elements :- \n",n);

  for(int i=0;i<n;i++)

  { scanf("%d",&var[i]); }

  printf("The given array is :- \n");

  for(int i=0;i<n;i++)

  { printf(" %d",var[i]); }

  printf("\nAfter removing the duplicates :- \n");

  for(int i=0;i<n;i++)

  {   for(int j=i+1;j<n;)

      { 
           if(var[j]==var[i])
            { 
               for(int z=j;z<n;z++)
 
               { var[z]=var[z+1]; }

               n--;
            }
            else
            { j++; }
    }
  }

  for(int i=0;i<n;i++)

  { printf(" %d",var[i]); }
}

Output:-



Hope you enjoyed the program. 
Feel free to comment down blow if you have any doubt.
Thank You.

Comments

Popular posts from this blog

TOP 10 PROGRAMMING LANGAUAGES COMMING 2021 | ARTICLE

Write a C-program to swap two number:

Print Fibonacci Series using Recursion | C program :