How to check if non of the number of a vector are odd N in C++

1 Answer

0 votes
#include <algorithm>
#include <iostream>
#include <vector>
  
int main() {
    std::vector<int> vec = { 2, 4, 6, 8, 12, 18, 20, 24 };
     

    if (std::none_of(vec.cbegin(), vec.cend(), std::bind(std::modulus<>(),
                                                     std::placeholders::_1, 2))) {
        std::cout << "None of the numbers are odd";
    }
}
     
     
       
      
/*
run:
      
None of the values are odd
      
*/

 



answered Aug 2, 2023 by avibootz

Related questions

1 answer 212 views
1 answer 113 views
2 answers 313 views
1 answer 228 views
...