输出围城(趣味题)大家他讨论一下?
输出扩展到N*N
3 3 3 3 3
3 2 2 2 3
3 2 1 2 3
3 2 2 2 3
3 3 3 3 3
#include<stdio.h>
#define abs(n) ((n)>0?(n):-(n))
#define max(x,y) ((x)>(y)?(x):(y))
#define num(n,i,j) max(abs((n)-(i)),abs((n)-(j)))+1
main(){
int n,i,j;
for(;;){
scanf(\"%d\",&n);
if(n<=0) break;
for(i=1;i<=2*n-1;i++){
for(j=1;j<=2*n-1;j++) printf(\"%4d\",num(n,i,j));
printf(\"\n\");
}
}
}
#include"stdio.h"
main()
{
int i,j,n;
input:
printf("Input n:");
scanf("%d",&n);
for(i=1;i<2*n;i++)
{
for(j=1;j<2*n;j++)
{
if(aabs(j,n)<=aabs(i,n))
printf("%3d",aabs(i,n)+1);
if(aabs(i,n)<aabs(j,n))
printf("%3d",aabs(j,n)+1);
}
printf("\n");
}
goto input;
}
int aabs(int a,int b)
{
if(a>b)
return (a-b);
else
return (b-a);
}