#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
while(1)
{
int n;
cout << "Please input the n " << endl;
cin >> n;
int a[n][n];
int circle = n - 1 , col = -1 , row = 0 , i = 0;
while(1)
{
if(circle < 0)
break;
i = i + 1;
col = col + 1;
a[row][col] = i;
if(circle == 0)
break;
for(int j = 0;j < circle;j ++)
{
i = i + 1;
col = col + 1;
a[row][col] = i;
}
for(int j = 0;j < circle;j ++)
{
i = i + 1;
row = row + 1;
a[row][col] = i;
}
for(int j = 0;j < circle;j ++)
{
i = i + 1;
col = col - 1;
a[row][col] = i;
}
for(int j = 0;j < circle - 1;j ++)
{
i = i + 1;
row = row - 1;
a[row][col] = i;
}
circle = circle - 2;
}
for(int j = 0;j < n;j ++)
{
for(int k = 0;k < n;k ++)
{
cout << left <<setw(4) << a[j][k];
}
cout << endl;
}
}
return 0;
}
#include <iomanip>
using namespace std;
int main()
{
while(1)
{
int n;
cout << "Please input the n " << endl;
cin >> n;
int a[n][n];
int circle = n - 1 , col = -1 , row = 0 , i = 0;
while(1)
{
if(circle < 0)
break;
i = i + 1;
col = col + 1;
a[row][col] = i;
if(circle == 0)
break;
for(int j = 0;j < circle;j ++)
{
i = i + 1;
col = col + 1;
a[row][col] = i;
}
for(int j = 0;j < circle;j ++)
{
i = i + 1;
row = row + 1;
a[row][col] = i;
}
for(int j = 0;j < circle;j ++)
{
i = i + 1;
col = col - 1;
a[row][col] = i;
}
for(int j = 0;j < circle - 1;j ++)
{
i = i + 1;
row = row - 1;
a[row][col] = i;
}
circle = circle - 2;
}
for(int j = 0;j < n;j ++)
{
for(int k = 0;k < n;k ++)
{
cout << left <<setw(4) << a[j][k];
}
cout << endl;
}
}
return 0;
}