how to count all distinct elements in an array in c++ ???

convert whole array to set -

```
int arr[N];
scanarr(arr,N)
set<int>my_set;
loop(i,n)
my_set.insert(arr[i])
print(my_set.size())
```

`unordered_map`

thanks much

but i am having some syntax error can you please provide the whole code!

thank

1 Like

I asked this question because i didn’t understood the solution given by Geeks for Geeks !

Its very simple.

#include<bits/stdc++.h>

using namespace std;

int main(){

int n;

cin>>n;

int a[n];

for(int i=0;i<n;i++){

cin>a[i];

}

sets(a,a+n);

cout<<s.size();

}

}

1 Like

Thanks

```
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int a[n];
set<int> my_set;
for(int i=0;i<n;i++){
cin>>a[i];
my_set.insert(a[i]);
}
cout<<my_set.size();
return 0;
}
```

1 Like