void nMatrix(int n)
{
int *p = new int[n*n];
int i, j, k, num, index, INC = 1;
num = 1;
k = n;
i = 0;
j = -1;
while(num <= n*n)
{
index = 0;
while(index++ < k)
{
j += INC;
*(p+i*n+j) = num;
num++;
}
k -= 1;
index = 0;
while(index++ < k)
{
i += INC;
*(p+i*n+j) = num;
num++;
}
INC = -INC;
}
cout << endl << n << "矩阵的回旋数为:/n/n";
for(i=0; i<n*n; i++)
{
cout << setw(5) << *(p+i) << ' ';
if((i+1)%n == 0)
cout << endl;
}
delete[] p;
}
{
int *p = new int[n*n];
int i, j, k, num, index, INC = 1;
num = 1;
k = n;
i = 0;
j = -1;
while(num <= n*n)
{
index = 0;
while(index++ < k)
{
j += INC;
*(p+i*n+j) = num;
num++;
}
k -= 1;
index = 0;
while(index++ < k)
{
i += INC;
*(p+i*n+j) = num;
num++;
}
INC = -INC;
}
cout << endl << n << "矩阵的回旋数为:/n/n";
for(i=0; i<n*n; i++)
{
cout << setw(5) << *(p+i) << ' ';
if((i+1)%n == 0)
cout << endl;
}
delete[] p;
}