打印一个 N*N 的方阵,N为每边 N=15 打印出下面图形字符的个数(3<N<20),要求最 TTTTTTTTTTTTTTT外一层为"T",第二层为"J",从第三层 TJJJJJJJJJJJJJT起每层依次打印数字 1,2,3,...TJ11111111111JT(右图以N
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/28 01:25:31
打印一个 N*N 的方阵,N为每边 N=15 打印出下面图形字符的个数(3<N<20),要求最 TTTTTTTTTTTTTTT外一层为"T",第二层为"J",从第三层 TJJJJJJJJJJJJJT起每层依次打印数字 1,2,3,...TJ11111111111JT(右图以N
打印一个 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"
void main()
{
char a[30][30];
int i,j,k,n,N;
printf("please input
N:
");
scanf("%d",&N);
for(i=0;i
打印一个 N*N 的方阵,N为每边 N=15 打印出下面图形字符的个数(3<N<20),要求最 TTTTTTTTTTTTTTT外一层为"T",第二层为"J",从第三层 TJJJJJJJJJJJJJT起每层依次打印数字 1,2,3,...TJ11111111111JT(右图以N
for(j='1',i=2;i<N/2+1;i++,j++)
ASCII码里49(十进制)是字符'1',写j=49和写j='1'是一样的.
这一句句式好杂糅啊,虽然的确是对的.
for(k=i;k<N-i;a[i][k]=j,a[k][i]=j,a[N-i-1][k]=j,a[k][N-i-1]=j,k++);写成这样一下就懂了
{
a[i][k]=j;
a[k][i]=j;
a[N-i-1][k]=j;
a[k][N-i-1]=j;
}
比如j=='1'时,把那一圈‘1’都填上.