[讨论]大家看看能不能精简一下
打印一个 N*N 的方阵,N为每边 N=15 打印出下面图形字符的个数(3<N<20), 要求最 TTTTTTTTTTTTTTT
外一层为"T", 第二层为"J", 从第三层 TJJJJJJJJJJJJJT
起每层依次打印数字 1,2,3,... TJ11111111111JT
(右图以N为15为例) TJ12222222221JT
TJ12333333321JT
TJ12344444321JT
TJ12345554321JT
TJ12345654321JT
TJ12345554321JT
TJ12344444321JT
TJ12333333321JT
TJ12222222221JT
TJ11111111111JT
TJJJJJJJJJJJJJT
TTTTTTTTTTTTTTT
#include<stdio.h>
#include<stdlib.h>
#define N 15
void main()
{
int i,j,c,k,l;
k=N-2;
l=3;
c=1;
for(i=1;i<=N;i++)
{
for(j=1;j<=N;j++)
{
if(i==N||j==N||i==1||j==1)
{
printf("T");
}
else if(i==(N-1) || j==(N-1) ||i==2||j==2)
{
printf("J");
}
else if(i==k||j==k||i==l||j==l)
{
printf("%d",1);
}
else if(i==(k-1)||j==(k-1)||i==(l+1)||j==(l+1))
{
printf("%d",2);
}
else if(i==(k-2)||j==(k-2)||i==(l+2)||j==(l+2))
{
printf("%d",3);
}
else if(i==(k-3)||j==(k-3)||i==(l+3)||j==(l+3))
{
printf("%d",4);
}
else if(i==(k-4)||j==(k-4)||i==(l+4)||j==(l+4))
{
printf("%d",5);
}
else
{
printf("%d",6);
}
}
printf("\n");
}
}
我的水平不够只能做到这里了!
呵呵