Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,870 questions

51,793 answers

573 users

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 167 views
1 answer 190 views
2 answers 225 views
1 answer 133 views
1 answer 139 views
1 answer 178 views
...