#include <iostream>
#include <iomanip> 
#include <ctime>
using namespace std;
int main() {
    ////////////////////////////////////// Задание 6 Вариант 1078 ///////////////////////////////////////////////
    srand ( time(NULL) );
    const int n = 5;
    const int m = 20; 
    int arr[m][n];
    int k;
    
    cout << "Элементы массива: " << endl; 
    
    //Заполнение массива случайными числами
    for(int i = 0; i < m;i++){
        for(int j = 0; j < n;j++){
            arr[i][j] =  rand() % 50;
            cout << setw(4) <<arr[i][j];
        }
        cout << endl;
    }
    
    cout << "Введите количество строк, которые необходимо перенести в конец :" ;
    cin >> k;
    cout << endl;
    int d = k;
    int X;
    
    for (int i = 0; i < m; ++i) {
        for (int j = 0; j < n; ++j) {
            if(i < k){
                X = arr[i][j];
                arr[i][j] = arr[m - d][j];
                arr[m - d][j] = X;
            }
        }
        d--;
    }
    
    for(int i = 0; i < m;i++){
        for(int j = 0; j < n;j++){
            cout << setw(4) <<arr[i][j];
        }
        cout << endl;
    }
    
    return 0;
}