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
下面是我编出来N=15的例子,但是我觉得我编的很麻烦,恳请达人帮我简化一下,最好能用上循环,这样能更好的模块化,谢谢阿。
#include<stdio.h>
void main()
{
int i,j,k=2;
for(i=0;i<15;i++,putchar('\n'))
{
for(j=0;j<15;j++)
{
if(i*j==0||j==14||i==14)
printf("T");
else if(i*j==j||i*j==i||j==13||i==13)
printf("J");
else if(i==k||j==k||j==15-k-1||i==15-k-1)
printf("%d",k-1);
else if(i==k+1||j==k+1||j==15-k-1-1||i==15-k-1-1)
printf("%d",k+1-1);
else if(i==k+2||j==k+2||j==15-k-2-1||i==15-k-2-1)
printf("%d",k+2-1);
else if(i==k+3||j==k+3||j==15-k-3-1||i==15-k-3-1)
printf("%d",k+3-1);
else if(i==k+4||j==k+4||j==15-k-4-1||i==15-k-4-1)
printf("%d",k+4-1);
else printf("%d",k+5-1);
}
}
}
[此贴子已经被作者于2006-11-18 11:22:00编辑过]