Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void Print(int* arr, int size) {
- for (int i = 0; i < size; i++) {
- cout << arr[i] << " ";
- }
- cout << endl;
- }
- void Fill(int* arr, int size) {
- for (int i = 0; i < size; i++) {
- arr[i] = rand() % 10;
- }
- }
- int main() {
- // удаление из массива четных элементов
- srand(time(NULL));
- setlocale(LC_ALL, "ru");
- int size;
- cout << "Введите размер массива: ";
- cin >> size;
- int* arr = new int[size];
- Fill(arr, size);
- Print(arr, size);
- int* temp = new int[size / 2];
- for (int i = 0, j = 0; i < size; i += 2, j++) {
- temp[j] = arr[i];
- }
- delete[] arr;
- arr = temp;
- size = size / 2;
- Print(arr, size);
- delete[] temp;
- }
Advertisement
Add Comment
Please, Sign In to add comment