C program to delete duplicate elements in an array

C program to delete duplicate elements in an array

This page has a c program to delete duplicate elements in an array. It is clear that, this C program will delete repeated (duplicated) elements using single array. For example:   If we enter 10 elements one by one to an array as 51 35 48 24 55 -43 48 35 24 29, then the program displays the elements, after removing Duplicates (in Ascending Order) are  -43  24  29  35   48  51  55The below given C program will Delete the duplicate elements using single array.  Kindly check out the program to Delete the duplicate elements in an array

Program to delete duplicate elements in an array


    #include<stdio.h>
    int main() {
                  int i, j, k, t, max, ar[30];
                  printf(" How many elements to the Array : ");
                  scanf("%d", &max);
                  printf("\n Enter %d elements one by one : \n", max);
                  for (i = 0; i < max; ++i)
                  scanf("%d", &ar[i]);
                  printf("\n\n The elements Before removing Duplicates are : \n");
                  for (i = 0; i < max; ++i)
                  printf("%d ", ar[i]);
                  for (i = 0; i < max; ++i){
                  for (j = i+1; j < max;)
                  if (ar[j] == ar[i]) {
                  for (k = j; k < max; ++k) {
                  ar[k] = ar[k + 1];
                  }
                  --max;
                  }
                  else
                  j++;
                  }
                  printf("\n\n The elements After removing Duplicates in Ascending Order are : \n");
                  for(j=0;j<max;j++){
                  for(k=j+1;k<max;k++)
                  if(ar[j]>ar[k])
                  { t=ar[j];
                   ar[j] = ar[k];
                   ar[k] =t;
                   }
                   printf("%d\n",ar[j]);
                   }
    return (0);
    }


Sample Output:                  

                  How many elements to the Array : 10
                  Enter 10 elements one by one :
                    51 35 48 24 55 -43 48 35 24 29
                 The elements After removing Duplicates in Ascending Order are
                      -43
                       24
                       29
                       35
                       48
                       51
                       55


Related Popular Posts:


*  Write a c program to check whether a given number is prime number or not?

 

*  Write a C program to find the prime numbers between 1 and 100

 

*  Write a C program to display the prime numbers between a range ?

 

*  Write a C program to find the prime numbers between a range using while loop?

 

*  Write a C program to find the sum of prime numbers between a range 

Other Related C Programs :


* C Program to find whether the given number is Odd or Even

* C Program to find the Sum of Odd Digits

* C Program to find the Sum of Even Digits

* C Program to find the Sum of Even and Odd Digits,

* C Program to Display Odd digits

* C Program to Display even digits

* C Program to Display Odd Numbers,

* C Program to Display Even Numbers,

* C Program to Check whether the given number is Armstrong number

* C Program to display the Armstrong numbers in Range

* C Program to display the Armstrong numbers between 1 and 1000

* C Program to check perfect number, perfect numbers in range

* C Program to Check Prime number, Prime numbers between 1 and 100

* C Program to display the Prime numbers in a Range

* C Program to display the Sum of Prime numbers

* C Program to Check Strong number

* C Program to display the Strong number in Range

* C Program to Check whether the given number is polindrome number or not

* C Program to Check polindrome number using for loop

* C Program to Check polindrome number using Recursion

* C Program to  check whether the given string is polindrome or not

* C Program to find the Roots of Quadratic equation

* C Program to display Fibonacci Series

* C Program to display the Fibonacci Series using an array

* C Program to display the Fibonacci Series using while loop

* C Program to find the Sum of Fibonacci Series, Factorial of Number

* C Program to find the Factorial without using Recursion

* C Program to find the Factorial using Pointers

* C Program to find the Factorial using Function

Bookmark and Share