fork download
  1. #include <algorithm>
  2. #include <functional>
  3. #include <iostream>
  4. #include <iterator>
  5. #include <numeric>
  6. #include <vector>
  7.  
  8. int main()
  9. {
  10. std::vector<int> v(10, 2);
  11. std::partial_sum(v.cbegin(), v.cend(), v.begin());
  12. std::cout << "Among the numbers: ";
  13. std::copy(v.cbegin(), v.cend(), std::ostream_iterator<int>(std::cout, " "));
  14. std::cout << '\n';
  15.  
  16. if (std::all_of(v.cbegin(), v.cend(), [](int i) { return i % 2 == 0; }))
  17. std::cout << "All numbers are even\n";
  18.  
  19. if (std::none_of(v.cbegin(), v.cend(), [](int i) { return i % 2 != 0; }))
  20. std::cout << "None of them are odd\n";
  21.  
  22. struct DivisibleBy
  23. {
  24. const int d;
  25. DivisibleBy(int n) : d(n) {}
  26. bool operator()(int n) const { return n % d == 0; }
  27. };
  28.  
  29. if (std::any_of(v.cbegin(), v.cend(), DivisibleBy(7)))
  30. std::cout << "At least one number is divisible by 7\n";
  31. }
Success #stdin #stdout 0s 5276KB
stdin
Standard input is empty
stdout
Among the numbers: 2 4 6 8 10 12 14 16 18 20 
All numbers are even
None of them are odd
At least one number is divisible by 7