fork(1) download
  1. #include <iostream>
  2. #include <vector>
  3. #include <numeric>
  4.  
  5. struct T
  6. {
  7. double a;
  8. double b;
  9. };
  10.  
  11. int main() {
  12. std::vector<T> v = {{1.0, 2.0}, {3.0, 4.0}, {5.0, 6.0}};
  13. std::cout << std::accumulate(v.begin(), v.end(), 0.0,
  14. [](double acc, const T &t){ return acc + t.a; }
  15. ) / v.size() << std::endl;
  16. std::cout << std::accumulate(v.begin(), v.end(), 0.0,
  17. [](double acc, const T &t){ return acc + t.b; }
  18. ) / v.size() << std::endl;
  19. return 0;
  20. }
Success #stdin #stdout 0.01s 5300KB
stdin
Standard input is empty
stdout
3
4