Count of composite integers in an array
unknown
c_cpp
2 years ago
448 B
8
Indexable
#include <iostream> #include <vector> bool isPrime(int n) { for (int i = 2; i * i <= n; ++i) if (n % i == 0) return false; return true; } int main() { std::vector<int> x; int n, input; std::cin >> n; for (int i = 0; i < n; ++i) { std::cin >> input; x.push_back(input); } int q = 0; for (int i = 0; i < x.size(); ++i) if (x[i] > 1 && !isPrime(x[i])) ++q; std::cout << q; return 0; }
Editor is loading...