#include <iostream>
#include <iomanip>
#include <cstdlib>
using namespace std;
int main()
{
setlocale(LC_ALL, "rus");
int c, k, p, r, s;
const int m = 6;//строки
const int n = 6;//столбцы
int a[m][n];
c = 1;
for (int i = 0; i < m; i++)
{
if (i % 2 == 0)
{
for (int j = n - 1; j >= 0; j--)
{
a[i][j] = c;
c++;
}
}
else
{
for (int j = 0; j < n; j++)
{
a[i][j] = c;
c++;
}
}
}
cout << "Исходная матрица ";
cout << " " << endl;
for (int i = 0; i < m; i++)
{
for (int j = 0; j < n; j++)
{
cout << a[i][j] << " ";
}
cout << endl;
}
if (m % 2 == 1)
c = a[m - 1][0];
else c = a[m - 1][n - 1];
s = c;
for (int i = m - 1; i > 0; i--)
{
if ((i + 1) % 2 == 1)
{
for (int j = 0; j < n - 1; j++)
{
a[i][j] = a[i][j + 1];
}
a[i][n - 1] = a[i - 1][n - 1];
}
else {
for (int j = n - 1; j > 0; j--)
a[i][j] = a[i][j - 1];
a[i][0] = a[i - 1][0];
}
}
for (int j = 0; j < n - 1; j++)
{
a[0][j] = a[0][j + 1];
}
a[0][n - 1] = c;
cout << "Искомая матрица ";
cout << " " << endl;
for (int i = 0; i < m; i++)
{
for (int j = 0; j < n; j++)
{
cout << a[i][j] << " ";
}
cout << endl;
}
return 0;
}