Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. #include <iostream>
  2. #include <time.h>
  3. using namespace std;
  4.  
  5. void init (int *, int);
  6. int *giveNewMem(int *, int, int );
  7. void murge(int *, int *, int ,int );
  8. void display (int *, int );
  9.  
  10. int main ()
  11. {
  12. int n = 6;
  13. int m = 3;
  14. int *arr1 = new int [n];
  15. int *arr2 = new int [m];
  16. init (arr1, n);
  17. cout << "\n";
  18. init (arr2, m);
  19. cout << "\n";
  20. arr1 = giveNewMem(arr1, n, m);
  21. murge(arr1, arr2, n, m);
  22. cout << "\n";
  23. display(arr1, n+m);
  24. system("pause");
  25. return 0;
  26. }
  27.  
  28. void init (int *mas, int n)
  29. {
  30. srand(time(0));
  31. for (int i = 0; i < n; i++)
  32. {
  33. *(mas + i) = rand() % 10;
  34. cout << *(mas + i) << " ";
  35. }
  36. }
  37.  
  38. void display (int *mas, int n)
  39. {
  40. for(int i = 0; i < n; i++)
  41. {
  42. cout << *(mas + i) << " ";
  43. }
  44. }
  45.  
  46. int *giveNewMem(int *arr, int n, int m)
  47. {
  48. int *newArr = new int [n + m];
  49. for(int i = 0; i < n; i++)
  50. {
  51. *(newArr + i) = *(arr + i);
  52. }
  53.  
  54. delete [] arr;
  55. return newArr;
  56. }
  57.  
  58. void murge(int *arr1, int *arr2, int n, int m)
  59. {
  60. for(int i = n; i < n + m; i++)
  61. {
  62. *(arr1 + i) = *(arr2 + i - n);
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement