Advertisement
Guest User

Untitled

a guest
Feb 17th, 2020
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. int s1=3, s2=5;
  6. int* a1 = new int[s1] {1,2,3};
  7. int* a2 = new int[s2] {10,20,30, 40, 50};
  8.  
  9. int* arr; // this is the merged array that you will create
  10. int sz; // what should be its size 'sz'?
  11.  
  12. // write your code here ...
  13. // .......
  14. sz = s1+s2;
  15. arr=new int [sz];
  16.  
  17. for(int i = 0 ; i<s1;i++)
  18. arr[i]=a1[i];
  19.  
  20. for(int i=0 ; i<s2;i++)
  21. arr[i+s1] = a2[i];
  22.  
  23. // do not forget to free the memory used by the two arrays here ...
  24. // ......
  25.  
  26. delete [] a1;
  27. delete [] a2;
  28. for (int i=0; i<sz; i++)
  29. cout << " " << arr[i];
  30.  
  31. // program finished
  32. delete [] arr;
  33. return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement