标签:
#include <stdio.h>
#define MAX 100
int main()
{
int number[MAX][MAX] = {0,};
int maxx, maxy, num, i, j, tmp_maxx, tmp_maxy, tmp_minx, tmp_miny;
scanf("%d %d", &maxx, &maxy);
num = 1;
tmp_maxx = tmp_maxy = 1;
tmp_minx = tmp_miny = 0;
i = j = 0;
number[j][i] = num++;
int x = 1;
while(num <= maxx * maxy){
for(i = tmp_maxx, j = tmp_miny; i >= tmp_minx || j <= tmp_maxy; i--, j++ )
number[j][i] = num++;
if(tmp_maxx + 1 > maxx -1)
tmp_miny++;
else
tmp_maxx++;
if(tmp_maxy + 1 > maxy -1)
tmp_minx++;
else
tmp_maxy++;
for(i = tmp_minx, j = tmp_maxy; i <= tmp_maxx || j >= tmp_miny; i++, j-- )
number[j][i] = num++;
if(tmp_maxx + 1 > maxx -1)
tmp_miny++;
else
tmp_maxx++;
if(tmp_maxy + 1 > maxy -1)
tmp_minx++;
else
tmp_maxy++;
}
for (i = 0; i < maxy; i++)
{
for (j = 0; j < maxx; j++)
printf("%2d ", number[i][j]);
printf("\n");
}
}
标签:
原文地址:http://www.cnblogs.com/famuji/p/5530768.html