35657

Untitled

Jan 11th, 2024
760
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1.  
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. void Print(int* arr, int size) {
  7.     for (int i = 0; i < size; i++) {
  8.         cout << arr[i] << " ";
  9.     }
  10.     cout << endl;
  11. }
  12.  
  13. void Fill(int* arr, int size) {
  14.     for (int i = 0; i < size; i++) {
  15.         arr[i] = rand() % 10;
  16.     }
  17. }
  18.  
  19. int main() {
  20.  
  21.     // удаление из массива четных элементов
  22.  
  23.     srand(time(NULL));
  24.     setlocale(LC_ALL, "ru");
  25.  
  26.     int size;
  27.  
  28.     cout << "Введите размер массива: ";
  29.     cin >> size;
  30.    
  31.     int* arr = new int[size];
  32.  
  33.     Fill(arr, size);
  34.  
  35.     Print(arr, size);
  36.  
  37.     int* temp = new int[size / 2];
  38.  
  39.  
  40.     for (int i = 0, j = 0;  i < size; i += 2, j++) {
  41.         temp[j] = arr[i];
  42.     }
  43.  
  44.     delete[] arr;
  45.  
  46.     arr = temp;
  47.     size = size / 2;
  48.  
  49.     Print(arr, size);
  50.  
  51.     delete[] temp;
  52. }
  53.  
Advertisement
Add Comment
Please, Sign In to add comment