fork download
  1. #include <iostream>
  2. #include <array>
  3. #include <random>
  4.  
  5. int main() {
  6. std::array<double, 17> rand_array;
  7. std::mt19937 rand_gen;
  8. std::uniform_real_distribution<double> dist(-17, 17);
  9. double Av=0;
  10. int Av_count=0;
  11. for (auto el:rand_array) {
  12. el=dist(rand_gen);
  13. std::cout<<el<<" ";
  14. if (el<0) Av_count++, Av+=el;
  15. }
  16. std::cout<<std::endl<<"AVG="<<Av/Av_count;
  17. return 0;
  18. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
-12.3938 11.3903 15.9415 -9.48484 -6.52232 1.6055 -10.595 16.758 16.8797 15.9016 7.67852 16.3577 -13.2647 10.1356 -6.901 -16.8374 -13.1762 
AVG=-11.1469