//旋转矩阵
#include<stdio.h>
#define MAX 1000
int a[MAX][MAX];
int matrix(int a[MAX][MAX],int low,int size,int number)
{
int i=low;
int j=low;
if(size==1)
{
a[size+1][size+1]=number;
return 0;
}
for(;i<size-1;i++)
{
a[j][i]=number;
number++;
}
for(;j<size-1;j++)
{
a[j][i]=number;
number++;
}
for(j=i;j>low;j--)
{
a[i][j]=number;
number++;
}
for(;i>low;i--)
{
a[i][j]=number;
number++;
}
matrix(a,low+1,size-1,number);
return 1;
}
void display(int a[MAX][MAX],int size)
{
for(int i=0;i<size;i++)
{
for(int j=0;j<size;j++)
{
printf("%3d",a[i][j]);
}
printf("/n");
}
}
int main()
{
matrix(a,0,10,1);
display(a,10);
return 0;
}
<!-- @page { margin: 2cm } TD P { margin-bottom: 0cm } P { margin-bottom: 0.21cm } -->
1 |
2 |
3 |
4 |
5 |
16 |
|
|
|
6 |
15 |
|
|
|
7 |
14 |
|
|
|
8 |
13 |
12 |
11 |
10 |
9 |