fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int arr[] = {1,2,4,3,5,1,5,1,3,4,1,4,5};
  6. int n = sizeof(arr)/sizeof(arr[0]);
  7.  
  8. bool vis[100] = {false};
  9. int count=0;
  10. for(int i =0; i < n ; i++){
  11. if(vis[arr[i]]==false){
  12. count++;
  13. vis[arr[i]] = true;
  14.  
  15. }
  16. }
  17. cout <<"number of distinct elements are: "<< count<<endl;
  18. return 0;
  19. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
number of distinct elements are: 5