Remove Duplicate Elements from Array
Here, you will get the example code to remove duplicate elements from array in c programming. In this program we will remove all the duplicate numbers in an array list.
In this program first, we will input some numbers in an array. Then we will process to check and remove duplicate elements from array.
Program to Remove Duplicate Elements from Array in C
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | #include<stdio.h> int main() { int array[10], temp[10], k,num,i,j,count=0; printf("\n Enter Number of elements : "); scanf("%d", &num); printf("\n Enter value of Array elements : "); for(i=0;i<num;i++) { scanf("%d", &array[i]); } printf("\n *****Array before remove duplicate Elements*****\n"); for(i=0;i<num;i++) { printf("%d ", array[i]); } for (i = 0; i < num; i++) { int j; for (j = 0; j < count; j++) { if (array[i] == temp[j]) break; } if (j == count) { temp[count] = array[i]; count++; } } printf("\n *****Array After remove duplicate Elements*****\n"); for(i=0;i<count;i++) { printf("%d ", temp[i]); } } |
Output
Enter Number of elements : 7
Enter value of Array elements : 1 2 3 4 3 6 2
*****Array before remove duplicate Elements*****
1 2 3 4 3 6 2
*****Array After remove duplicate Elements*****
1 2 3 4 6
Check out our other C programming Examples