52 lines
913 B
C++
52 lines
913 B
C++
#include <iostream>
|
|
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;
|
|
} |