Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- int s1=3, s2=5;
- int* a1 = new int[s1] {1,2,3};
- int* a2 = new int[s2] {10,20,30, 40, 50};
- int* arr; // this is the merged array that you will create
- int sz; // what should be its size 'sz'?
- // write your code here ...
- // .......
- sz = s1+s2;
- arr=new int [sz];
- for(int i = 0 ; i<s1;i++)
- arr[i]=a1[i];
- for(int i=0 ; i<s2;i++)
- arr[i+s1] = a2[i];
- // do not forget to free the memory used by the two arrays here ...
- // ......
- delete [] a1;
- delete [] a2;
- for (int i=0; i<sz; i++)
- cout << " " << arr[i];
- // program finished
- delete [] arr;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement