Advertisement
Spocoman

01. Zig-Zag Arrays

Nov 18th, 2023
765
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     const int MAX_SIZE = 99;
  7.     int numbers1[MAX_SIZE]{};
  8.     int numbers2[MAX_SIZE]{};
  9.  
  10.     int arrSize, n1, n2;
  11.     cin >> arrSize;
  12.  
  13.     for (int i = 0; i < arrSize; i++) {
  14.         if (i % 2 == 0) {
  15.             cin >> numbers1[i];
  16.             cin >> numbers2[i];
  17.         }
  18.         else {
  19.             cin >> numbers2[i];
  20.             cin >> numbers1[i];
  21.         }
  22.     }
  23.  
  24.     for (int i = 0; i < arrSize; i++) {
  25.         cout << numbers1[i] << ' ';
  26.     }
  27.     cout << endl;
  28.  
  29.     for (int i = 0; i < arrSize; i++) {
  30.         cout << numbers2[i] << ' ';
  31.     }
  32.     cout << endl;
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement