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