fork download
  1. #include <vector>
  2. #include <algorithm>
  3. #include <iostream>
  4.  
  5. int main()
  6. {
  7. std::vector<int> a = { 1,2,3,4,5,6,7 };
  8.  
  9. int sum=0, product=1;
  10.  
  11. std::for_each(a.begin(), a.end(), [&] (int i) { sum+=i; product*=i; });
  12.  
  13. std::cout << "sum: " << sum << ", product: " << product << std::endl;
  14.  
  15. return 0;
  16. }
  17.  
Success #stdin #stdout 0s 2960KB
stdin
Standard input is empty
stdout
sum: 28, product: 5040