Advertisement
Spocoman

03. Print in Parts

Feb 9th, 2024 (edited)
916
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.51 KB | None | 0 0
  1. #include <iostream>
  2. #include <memory>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.     int row, col, r, c;
  8.     cin >> row >> col;
  9.  
  10.     int matrixElements = row * col;
  11.  
  12.     unique_ptr<int[]> matrix = make_unique<int[]>(matrixElements);
  13.  
  14.     for (int i = 0; i < matrixElements; i++) {
  15.         cin >> matrix[i];
  16.     }
  17.  
  18.     cin >> r >> c;
  19.  
  20.     for (int i = 0; i < r; i++) {
  21.         for (int j = 0; j < c; j++) {
  22.             cout << matrix[i * col + j] << ' ';
  23.         }
  24.         cout << endl;
  25.     }
  26.     return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement