打印一个 N*N 的方阵,N为每边 N=15
打印出下面图形字符的个数(3<N<20), TTTTTTTTTTTTT
要求最外一层为"T", 第二层为"J", 从第三层 TJJJJJJJJJJJJJJJJT
起每层依次打印数字 1,2,3,... (右图以N为15为例) TJ11111111111JT
TJ12222222221JT
打印出下面图形字符的个数(3<N<20), TTTTTTTTTTTTT
要求最外一层为"T", 第二层为"J", 从第三层 TJJJJJJJJJJJJJJJJT
起每层依次打印数字 1,2,3,... (右图以N为15为例) TJ11111111111JT
TJ12222222221JT
TJ12333333321JT
TJ12344444321JT
TJ12345554321JT
TJ12345654321JT
TJ12345554321JT
TJ12344444321JT
TJ12333333321JT
TJ12222222221JT
TJ11111111111JT
TJJJJJJJJJJJJJJJJT
TTTTTTTTTTTTT
程序如下:
#include"stdio.h"
#include"stdlib.h"
void main()
{
char a[30][30];
int i,j,k,n,N;
printf("please input N: ");
scanf("%d",&N);
for(i=0;i<N;i++)
{
a[0][i]='T',a[N-1][i]='T',a[i][0]='T',a[i][N-1]='T';
}
for(i=1;i<N-1;i++)
{
a[1][i]='J',a[N-2][i]='J',a[i][1]='J',a[i][N-2]='J';
}
for(j=49,i=2;i<N/2+1;i++,j++)
for(k=i;k<N-i;k++)
{
a[i][k]=j,a[k][i]=j,a[N-i-1][k]=j,a[k][N-i-1]=j;
}
for(i=0;i<N;i++)
{
for(j=0;j<N;j++)
printf("%c ",a[i][j]);
printf("\n");
}
}