#include
#include
void printMatrix(int **matrix,int columns,int rows,int start)
{
int x=columns-start-1;
int y=rows-start-1;
int i;
for(i&#61;start;i<&#61;x;i&#43;&#43;)//先打印一行
printf("%d ",matrix[start][i]);
if(start
{
for(i&#61;start&#43;1;i<&#61;y;i&#43;&#43;)
printf("%d ",matrix[i][x]);
}
if(x>start&&y>start)//从右到左打印
{
for(i&#61;x-1;i>&#61;start;i--)
printf("%d ",matrix[y][i]);
}
if(x>start&&y>start&#43;1)//从下到上打印
{
for(i&#61;y-1;i>&#61;start&#43;1;i--)
printf("%d ",matrix[i][start]);
}
}
void matrixClock(int **matrix,int columns,int rows)
{
if(matrix&#61;&#61;NULL||columns<&#61;0||rows<&#61;0)
return;
int start&#61;0;
while(columns>start*2&&rows>start*2)
{
printMatrix(matrix,columns,rows,start);
start&#43;&#43;;
}
}
int main()
{
int n,m;
while(scanf("%d %d",&n,&m)!&#61;NULL)
{
int **numbers;
int i,j;
numbers&#61;(int **)malloc(sizeof(int *)*n);//n rows
for(i&#61;0;i
numbers[i]&#61;(int *)malloc(sizeof(int)*m);//m columns
for(i&#61;0;i
for(j&#61;0;j
scanf("%d",&numbers[i][j]);
matrixClock(numbers,m,n);
}
return 0;
}