Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.05 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. bool IsPrime(int num) {
  6.     for (int i = 2; i<=num/2; i++) {
  7.         if (num%i == 0) {
  8.             return false;
  9.         }
  10.     }
  11.     return true;
  12. }
  13.  
  14. class myArray {
  15. private:
  16.     int N;
  17.     int* array;
  18. public:
  19.     myArray(int N) : N{N} {
  20.     array = new int(N);
  21.     }
  22.     myArray() : N{5} {
  23.     array = new int[N];
  24.     }
  25.  
  26.     ~myArray () {
  27.         delete[] array;
  28.     }
  29.     void setElem() {
  30.         cout <<"Введите элементы массива" << endl;
  31.         for (int i = 0; i < N; i++) {
  32.             //cin >> array[i];
  33.             array[i] = rand() % 100;
  34.         }
  35.     }
  36.     void PrimeCount(int P) {
  37.         int counter = 0;
  38.         for (int i = 0; i < N; i++) {
  39.             if (array[i] > P) {
  40.                 if (IsPrime(array[i])) {
  41.                     counter++;
  42.                     cout << "Простое число:" <<  array[i] << endl;
  43.                 }
  44.             }
  45.         }
  46.         cout << "Количество простых чисел в массиве, больше " << P << ": " << counter << endl;
  47.     }
  48. };
  49.  
  50.  
  51. int main() {
  52.     int p;
  53.     cout << "Введите N" << endl;
  54.     cin >> p;
  55.     myArray massiv(p);
  56.     massiv.setElem();
  57.     massiv.PrimeCount(15);
  58.     return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement