Advertisement
Vla_DOS

1. покажчики

Apr 1st, 2023
488
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5.     int n;
  6.     cout << "Enter the number of elements in the array: ";
  7.     cin >> n;
  8.  
  9.     int* arr = new int[n]; // виділення пам'яті для масиву
  10.  
  11.     cout << "Enter the elements of the array:" << endl;
  12.     for (int i = 0; i < n; i++) {
  13.         cin >> *(arr + i); // введення елементів масиву
  14.     }
  15.  
  16.     cout << "Even elements of the array: ";
  17.     for (int i = 0; i < n; i++) {
  18.         if (*(arr + i) % 2 == 0) { // перевірка на парність
  19.             cout << *(arr + i) << " ";
  20.         }
  21.     }
  22.  
  23.     delete[] arr; // звільнення пам'яті
  24.     return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement