Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // lab1.8.cpp: определяет точку входа для консольного приложения.
- //
- #include "stdafx.h"
- #include <iostream>
- #include <ctime>
- using namespace std;
- void push(int *& arr, int &length, int value) {
- int * other = new int[length + 1];
- for (int i = 0; i < length; i++)
- {
- other[i] = arr[i];
- }
- delete[] arr;
- other[length] = value;
- length++;
- arr = other;
- }
- int main()
- {
- setlocale(LC_ALL, "Rus");
- srand(time(NULL));
- int K = 1 + rand() % 15;
- int N = 1 + rand() % 15;
- int length = 0;
- int * arr1 = new int[K];
- int * arr2 = new int[N];
- int * arr3 = new int[length];
- for (int i = 0; i < K; i++)
- {
- arr1[i] = 1 + rand() % 20;
- if (arr1[i] % 2 == 0) {
- push(arr3, length, arr1[i]);
- }
- }
- for (int i = 0; i < N; i++)
- {
- arr2[i] = 1 + rand() % 20;
- if (arr2[i] % 2 == 0) {
- push(arr3, length, arr2[i]);
- }
- }
- cout << "1-ый массив: " << endl;
- for (int i = 0; i < K; i++)
- {
- cout << arr1[i] << " ";
- }
- cout << endl;
- cout << "\n2-ой массив: " << endl;
- for (int i = 0; i < N; i++)
- {
- cout << arr2[i] << " ";
- }
- cout << endl;
- cout << "\nмассив с четными числами обоих массивов: " << endl;
- for (int i = 0; i < length; i++)
- {
- cout << arr3[i] << " ";
- }
- cout << endl;
- delete[] arr1;
- delete[] arr2;
- delete[] arr3;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement