How to count the total number from int array that divide by N using bind function in C++

1 Answer

0 votes
#include <iostream>
#include <algorithm>
 
using namespace std::placeholders;
  
bool is_divide_by(int n , int d) {
    return n % d == 0;
}
  
int main() {
    int arr[10] = {4, 45, 76, 12, 63, 98, 83273, 62, 23, 100};
    int n = 3;
      
    int count = std::count_if(arr, arr + sizeof(arr)/sizeof(int) , std::bind(&is_divide_by, _1, n));
     
    // 45 12 63
    std::cout << "total = " << count; 
}
  
  
  
/*
run:
  
total = 3
  
*/

 



answered Feb 5, 2020 by avibootz
edited Aug 1, 2023 by avibootz

Related questions

1 answer 194 views
1 answer 214 views
2 answers 251 views
1 answer 212 views
1 answer 153 views
1 answer 170 views
...