Advertisement
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;
- }
- }
- bool is_simple(int number) {
- for (int i = 2; i <= number / 2; i++) {
- if (number % i == 0) {
- return false;
- }
- }
- return true;
- }
- void remove_simple(int*& arr, int& size) {
- int temp_size = size;
- int* temp = new int[temp_size];
- int count = 0;
- for (int i = 0; i < size; i++) {
- if (!is_simple(arr[i])) {
- temp[count++] = arr[i];
- }
- }
- delete[] arr;
- arr = new int[count];
- size = count;
- for (int i = 0; i < size; i++) {
- arr[i] = temp[i];
- }
- delete[] temp;
- }
- int main() {
- setlocale(LC_ALL, "ru");
- srand(time(NULL));
- int size;
- cout << "Введите размер массива: ";
- cin >> size;
- int* arr = new int[size];
- fill(arr, size);
- print(arr, size);
- remove_simple(arr, size);
- print(arr, size);
- delete[] arr;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement