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,938 questions

51,875 answers

573 users

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

1 Answer

0 votes
#include <iostream>

using namespace std;

bool is_divide_by(int n , int d) {
    if (n % d == 0)
        return true;
    return false;
}

int main() {
    int arr[10] = {4, 45, 76, 12, 63, 98, 83273, 62, 23, 100};
    int count = 0, n = 3;
    
    for (int i = 0; i < sizeof(arr)/sizeof(int); i++) {
        if (is_divide_by(arr[i], 3)) {
            cout << arr[i] << endl;
            count++;
        }
    }
    
    cout << "total = " << count;
}



/*
run:

45
12
63
total = 3

*/

 



answered Feb 5, 2020 by avibootz

Related questions

1 answer 191 views
2 answers 225 views
1 answer 178 views
2 answers 54 views
1 answer 133 views
...