Добавить task5.cpp
This commit is contained in:
52
task5.cpp
Normal file
52
task5.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user