avr39ripe

cppArr2DBigSmallSum

Apr 19th, 2021 (edited)
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.95 KB | None | 0 0
  1. #include <iostream>
  2. #include <chrono>
  3.  
  4. int main()
  5. {
  6.     srand(time(0));
  7.     const int arrSizeY{ 5 };
  8.     const int arrSizeXBig{ 10 };
  9.     const int arrSizeXSmall{ arrSizeXBig / 2 };
  10.  
  11.     int arrBig[arrSizeY][arrSizeXBig]{ {1,2,3,4,5,6,7,8,9,10},{1,2,3,4,5,6,7,8,9,10},{1,2,3,4,5,6,7,8,9,10},{1,2,3,4,5,6,7,8,9,10},{1,2,3,4,5,6,7,8,9,10} };
  12.     int arrSmall[arrSizeY][arrSizeXSmall]{ 0 };
  13.  
  14.     for (int y{ 0 }; y < arrSizeY; ++y)
  15.     {
  16.         for (int x{ 0 }; x < arrSizeXBig; ++x)
  17.         {
  18.             arrBig[y][x] = rand() % 10;
  19.             std::cout << arrBig[y][x] << '\t';
  20.  
  21.         }
  22.         std::cout << '\n';
  23.     }
  24.     std::cout << '\n';
  25.  
  26.     for (int y{ 0 }; y < arrSizeY; ++y)
  27.     {
  28.         for (int x{ 0 }; x < arrSizeXSmall; ++x)
  29.         {
  30.             arrSmall[y][x] = (arrBig[y][x * 2] + arrBig[y][x * 2 + 1]);
  31.             std::cout << arrSmall[y][x] << '\t';
  32.         }
  33.         std::cout << '\n';
  34.     }
  35.  
  36.     return 0;
  37. }
Add Comment
Please, Sign In to add comment