#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
srand(unsigned(time(0)));
size_t n = 2 * rand() % 6 + 5, m = n;
int** array = new int* [n];
for (auto x = 0; x < n; x++)
{
array[x] = new int[m];
}
for (size_t x = 0; x < n; x++)
{
for (size_t y = 0; y < m; y++)
{
array[x][y] = 0;
}
}
unsigned h = 1; int p = 1;
for (size_t y = 0; y < m / 2; y++)
{
if (n - h == 0)
{
break;
}
for (size_t r = h; r < n - h; r++)
{
array[r][y] = p++;
}
h++;
}
for (size_t y = m / 2; y < m; y++)
{
if (n - h == 0)
{
break;
}
for (size_t r = h; r < n - h; r++)
{
array[r][y] = p++;
}
h--;
if (!h)
{
break;
}
}
for (size_t x = 0; x < n; x++)
{
for (size_t y = 0; y < m; y++)
{
cout << setw(5) << array[x][y];
}
cout << endl;
}
return 0;
}