From a5da8d2fee18943436329f4ae0ce56f2a694d7b7 Mon Sep 17 00:00:00 2001 From: Misha Date: Tue, 30 Sep 2025 20:38:38 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D1=82?= =?UTF-8?q?=D1=8C=20task5.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- task5.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 task5.cpp diff --git a/task5.cpp b/task5.cpp new file mode 100644 index 0000000..7e18034 --- /dev/null +++ b/task5.cpp @@ -0,0 +1,52 @@ +#include +using namespace std; + +void addBlock(int*& a, int& n, const int* b, int m) { + int* temp = new int[n + m]; + + for (int i = 0; i < n; i++) { + temp[i] = a[i]; + } + + for (int i = 0; i < m; i++) { + temp[n + i] = b[i]; + } + + delete[] a; + + a = temp; + + n = n + m; +} + +int main() { + srand(time(0)); + + int n = 7, m = 4; + int* a = new int[n]; + int* b = new int[m]; + + cout << "A: "; + for (int i = 0; i < n; i++) { + a[i] = rand() % 30; + cout << a[i] << (i < n - 1 ? " " : ""); + } + + cout << endl << "B: "; + for (int i = 0; i < m; i++) { + b[i] = rand() % 30; + cout << b[i] << (i < m - 1 ? " " : ""); + } + + addBlock(a, n, b, m); + + cout << endl << "Result: "; + for (int i = 0; i < n; i++) { + cout << a[i] << (i < n - 1 ? " " : ""); + } + cout << endl; + + delete[] a; + delete[] b; + return 0; +} \ No newline at end of file