Advertisement
Guest User

Untitled

a guest
Mar 20th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. // lab1.8.cpp: определяет точку входа для консольного приложения.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. #include <ctime>
  7. using namespace std;
  8.  
  9. void push(int *& arr, int &length, int value) {
  10. int * other = new int[length + 1];
  11. for (int i = 0; i < length; i++)
  12. {
  13. other[i] = arr[i];
  14. }
  15. delete[] arr;
  16. other[length] = value;
  17. length++;
  18. arr = other;
  19. }
  20.  
  21. int main()
  22. {
  23. setlocale(LC_ALL, "Rus");
  24. srand(time(NULL));
  25. int K = 1 + rand() % 15;
  26. int N = 1 + rand() % 15;
  27. int length = 0;
  28. int * arr1 = new int[K];
  29. int * arr2 = new int[N];
  30. int * arr3 = new int[length];
  31. for (int i = 0; i < K; i++)
  32. {
  33. arr1[i] = 1 + rand() % 20;
  34. if (arr1[i] % 2 == 0) {
  35.  
  36. push(arr3, length, arr1[i]);
  37. }
  38. }
  39. for (int i = 0; i < N; i++)
  40. {
  41. arr2[i] = 1 + rand() % 20;
  42. if (arr2[i] % 2 == 0) {
  43.  
  44. push(arr3, length, arr2[i]);
  45. }
  46. }
  47. cout << "1-ый массив: " << endl;
  48. for (int i = 0; i < K; i++)
  49. {
  50. cout << arr1[i] << " ";
  51. }
  52. cout << endl;
  53. cout << "\n2-ой массив: " << endl;
  54. for (int i = 0; i < N; i++)
  55. {
  56. cout << arr2[i] << " ";
  57. }
  58. cout << endl;
  59. cout << "\nмассив с четными числами обоих массивов: " << endl;
  60. for (int i = 0; i < length; i++)
  61. {
  62. cout << arr3[i] << " ";
  63. }
  64. cout << endl;
  65. delete[] arr1;
  66. delete[] arr2;
  67. delete[] arr3;
  68.  
  69. return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement