Advertisement
avr39ripe

cpp2DArrRevFwOutput

Apr 7th, 2021
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.09 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. int main()
  4. {
  5.    
  6.     const int arrSizeY{ 4 };
  7.     const int arrSizeX{ 4 };
  8.  
  9.     const int arrSize{ arrSizeY * arrSizeX };
  10.  
  11.     int arrFlat[arrSize]{ 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 };
  12.  
  13.     int arr[arrSizeY][arrSizeX]{ {1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,16} };
  14.  
  15.     int direction{ 1 };
  16.     int begin{0};
  17.     int end{0};
  18.  
  19.    
  20.  
  21.     for (int y{ 0 }; y < arrSizeY; ++y, direction *= -1)
  22.     {
  23.         if (direction == 1)
  24.         {
  25.             begin = 0;
  26.             end = arrSizeX;
  27.         }
  28.         else
  29.         {
  30.             begin = arrSizeX - 1;
  31.             end = -1;
  32.         }
  33.  
  34.         for (; begin != end;begin += direction)
  35.         {
  36.             std::cout << arr[y][begin] << '\t';
  37.             //std::cout << arrFlat[y * arrSizeX + x] << '\t';
  38.         }
  39.         std::cout << '\n';
  40.  
  41.         //if (y % 2 != 0)
  42.         //{
  43.         //  for (int x{ 0 }; x < arrSizeX; ++x)
  44.         //  {
  45.         //      std::cout << arr[y][x] << '\t';
  46.         //      //std::cout << arrFlat[y * arrSizeX + x] << '\t';
  47.         //  }
  48.         //}
  49.         //else
  50.         //{
  51.         //  for (int x{ arrSizeX - 1 }; x >= 0; --x)
  52.         //  {
  53.         //      std::cout << arr[y][x] << '\t';
  54.         //      //std::cout << arrFlat[y * arrSizeX + x] << '\t';
  55.         //  }
  56.         //}
  57.         //
  58.        
  59.        
  60.     }
  61.    
  62.     return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement