Below is the program to remove duplicate elements in an array.
#include <stdio.h>
int main() {
int n,i,j,k;
printf("Enter how many numbers do you want to enter:");
scanf("%d",&n);
int arr[n];
printf("Enter elements: ");
for(i=0;i<n;i++){
scanf("%d",&arr[i]);
}
printf("Elements in the array are:\n");
for(i=0;i<n;i++){
printf("%d\n",arr[i]);
}
for(i=0;i<n;i++){
for(j=i+1;j<n;j++){
if(arr[i]==arr[j]){
for(k=j; k<n; k++){
arr[k]=arr[k+1];
}
n--;
j--;
}
}
}
printf("Elements in the array are:\n");
for(i=0;i<n;i++){
printf("%d\n",arr[i]);
}
}
Output:
Enter how many numbers do you want to enter:8
Enter elements: 7
5
9
3
2
5
7
9
Elements in the array are:
7
5
9
3
2
5
7
9
Elements in the array are:
7
5
9
3
2