fork download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. int main() {
  6. vector<int> arr = {1,1,1,1,2,3,4,5,3,3,4,5,3,4,5,6,3,5,6,9,0,0,0,10,10};
  7. vector<int> arr2(11,0);
  8.  
  9. for(int i =0 ; i< arr.size();i++){
  10. arr2[arr[i]]++;
  11. }
  12. for(int i =0 ; i <= 10; i++){
  13. cout<< "No of times "<<i<<" occured in the array is: "<< arr2[i]<<endl;
  14. }
  15. return 0;
  16. }
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
No of times 0 occured in the array is: 3
No of times 1 occured in the array is: 4
No of times 2 occured in the array is: 1
No of times 3 occured in the array is: 5
No of times 4 occured in the array is: 3
No of times 5 occured in the array is: 4
No of times 6 occured in the array is: 2
No of times 7 occured in the array is: 0
No of times 8 occured in the array is: 0
No of times 9 occured in the array is: 1
No of times 10 occured in the array is: 2