Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- bool IsPrime(int num) {
- for (int i = 2; i<=num/2; i++) {
- if (num%i == 0) {
- return false;
- }
- }
- return true;
- }
- class myArray {
- private:
- int N;
- int* array;
- public:
- myArray(int N) : N{N} {
- array = new int(N);
- }
- myArray() : N{5} {
- array = new int[N];
- }
- ~myArray () {
- delete[] array;
- }
- void setElem() {
- cout <<"Введите элементы массива" << endl;
- for (int i = 0; i < N; i++) {
- //cin >> array[i];
- array[i] = rand() % 100;
- }
- }
- void PrimeCount(int P) {
- int counter = 0;
- for (int i = 0; i < N; i++) {
- if (array[i] > P) {
- if (IsPrime(array[i])) {
- counter++;
- cout << "Простое число:" << array[i] << endl;
- }
- }
- }
- cout << "Количество простых чисел в массиве, больше " << P << ": " << counter << endl;
- }
- };
- int main() {
- int p;
- cout << "Введите N" << endl;
- cin >> p;
- myArray massiv(p);
- massiv.setElem();
- massiv.PrimeCount(15);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement