Qn: Write a C program to remove the duplicates in an array?
-By Admin test, Last Update On 4th January,2020 11:55 am

Remove Duplicates From Array

#include <stdio.h>
int main(){
int n=12, b[100], count = 0, i, j;
int a[]={2,8,3,6,3,5,7,2,6,9,2,8};
for (i=0;i<n;i++){
	for (j=0;j<count;j++){
     if(a[i] == b[j])
     break;
     }
     if (j==count){
     b[count]=a[i];
     count++;
     }
}
     printf("Array after removing duplicate elements:\n");
 for (i=0;i<count;i++){
 	printf(\"%d\n", b[i]);
}
return 0;
}

Output:

Array after removing duplicate elements:
2
8
3
6
5
7
9

Pgcomments

Comments