Qn: Write a C++ program to remove the duplicates in an array?
-By Admin, Last Update On 30th May,2019 11:43 pm

Program

#include<iostream.h>
#include<conio.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++;
    }
  }
cout<<"Array after removing duplicate elements:\n";
  for (i=0;i<count;i++){
    cout<<b[i];
    }
  return 0;
}

Output:

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

Pgcomments

Comments