Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <time.h>
- using namespace std;
- void init (int *, int);
- int *giveNewMem(int *, int, int );
- void murge(int *, int *, int ,int );
- void display (int *, int );
- int main ()
- {
- int n = 6;
- int m = 3;
- int *arr1 = new int [n];
- int *arr2 = new int [m];
- init (arr1, n);
- cout << "\n";
- init (arr2, m);
- cout << "\n";
- arr1 = giveNewMem(arr1, n, m);
- murge(arr1, arr2, n, m);
- cout << "\n";
- display(arr1, n+m);
- system("pause");
- return 0;
- }
- void init (int *mas, int n)
- {
- srand(time(0));
- for (int i = 0; i < n; i++)
- {
- *(mas + i) = rand() % 10;
- cout << *(mas + i) << " ";
- }
- }
- void display (int *mas, int n)
- {
- for(int i = 0; i < n; i++)
- {
- cout << *(mas + i) << " ";
- }
- }
- int *giveNewMem(int *arr, int n, int m)
- {
- int *newArr = new int [n + m];
- for(int i = 0; i < n; i++)
- {
- *(newArr + i) = *(arr + i);
- }
- delete [] arr;
- return newArr;
- }
- void murge(int *arr1, int *arr2, int n, int m)
- {
- for(int i = n; i < n + m; i++)
- {
- *(arr1 + i) = *(arr2 + i - n);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement