Advertisement
avr39ripe

PV024arr2DBasics

Nov 4th, 2020 (edited)
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.01 KB | None | 0 0
  1. #include <iostream>
  2.  
  3.  
  4. int main()
  5. {
  6.     const int sizeY{ 3 };
  7.     const int sizeX{ 4 };
  8.     const int sizeZ{ 2 };
  9.     int arr2d[sizeY][sizeX]{ {1,212,3,4},{15,6,7,8},{9,10,111,12} };
  10. //  {
  11. //      0   1   2   3   x      
  12. //  0   {1, 2,  3,  4},
  13. //  1   {5, 6,  7,  8},
  14. //  2   {9, 10, 11, 12}
  15. //  y
  16. //  };
  17.  
  18.     int arr3d[sizeY][sizeX][sizeZ]
  19.     {
  20.         {{1,2}, {3,4}, {5,6}, {7,8}},
  21.         {{9,10}, {11,12}, {13,14}, {15,16}},
  22.         {{17,18}, {19,20}, {21,22}, {23,24}}
  23.     };
  24.  
  25.     arr3d[1][2][1]; //14
  26.     arr3d[2][0][1]; //18
  27.  
  28.  
  29.     char arr2DChar[2][3]
  30.     {
  31.         {'a','b','c'},
  32.         {'d','e','f'}
  33.     };
  34.  
  35.  
  36.     int maxIdx{0};
  37.     int max;
  38.     //max = arr2d[0][0];
  39.  
  40.     for (int y{ 0 }; y < sizeY; ++y)
  41.     {
  42.         //maxIdx = 0;
  43.         max = arr2d[y][0];
  44.         for (int x{ 0 }; x < sizeX; ++x)
  45.         {
  46.             //if (arr2d[y][x] > arr2d[y][maxIdx])
  47.             //{
  48.             //  maxIdx = x;
  49.             //}
  50.             if (arr2d[y][x] > max)
  51.             {
  52.                 max = arr2d[y][x];
  53.             }
  54.  
  55.             std::cout << arr2d[y][x] << ' ';
  56.         }
  57.         //std::cout << " max = " << arr2d[y][maxIdx] << '\n';
  58.         std::cout << " max = " << max << '\n';
  59.     }
  60.  
  61.  
  62.     return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement