Advertisement
xxeell

DZ_for_kartosha_with_3_arrays

Nov 28th, 2018
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdlib.h>
  3. #include <ctime>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     int n;
  10.     srand(time(0));
  11.     n = rand() % 8 + 2;
  12.     int *A = new int[n];
  13.     for (int i = 0; i < n; i++)
  14.     {
  15.         A[i] = 2*i+1;
  16.         cout << A[i] << " ";
  17.     }
  18.  
  19.     cout << endl;
  20.  
  21.     int *B = new int[n];
  22.     for (int i = 0; i < n; i++)
  23.     {
  24.         B[i] = 2*(i+1);
  25.         cout << B[i] << " ";
  26.     }
  27.  
  28.     cout << endl;
  29.  
  30.     int tn = n + n;
  31.     int *C = new int[tn];
  32.     for (int i = 0; i < tn; i += 2)
  33.     {
  34.         C[i] = A[i / 2];
  35.         C[i + 1] = B[i / 2];
  36.  
  37.         cout << C[i] << " " << C[i + 1] << " ";
  38.     }
  39.  
  40.  
  41.     delete[] A;
  42.     delete[] B;
  43.     delete[] C;
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement