fork(1) download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. static const int COUNT = 2500000;
  5.  
  6. int main() {
  7. std::vector<int> data{1, 2, 3, 4, 5};
  8.  
  9. int summ = 0;
  10. for (int i = 0; i < COUNT; i++) {
  11. int idx = rand() % 10;
  12. if (idx < data.size()) summ += data[idx];
  13. }
  14.  
  15. std::cout << double(summ) / COUNT << std::endl;
  16.  
  17. return 0;
  18. }
Success #stdin #stdout 0.04s 4392KB
stdin
Standard input is empty
stdout
1.50023