用c语言编程序输出以下图形

2025-01-08 09:50:40
推荐回答(3个)
回答1:

#include
#include
int main(void)
{
char ch;
char str[53][53];
int m = 0, n = 0, i = 0;
int counter = 0, len = 0;

//memset((void*)str, '\0', 53*53);
printf("Please insert a letter(A-Z): ");
scanf("%c", &ch);

if( ch<65 || ch > 90){
printf("A-Z is allowed only\n");
exit(0);
}

for(i = 65; i <= ch; i++){
counter++;
//printf("i = %d, counter = %d\n", i, counter);
}
i--;

len = 2*counter - 1;

//printf("i = %d, counter = %d, len = %d\n", i, counter, len);
for(m = 0; m < counter; m++){
for(n = 0; n < counter; n++){
if(m <= n)
str[m][n] = 'A'+m;//2
if(n > m){
str[n][m] = 'A'+m;//1
}
}
}

for(m = 0; m < counter; m++){
for(n = counter; n < len; n++){
str[m][n] = str[m][len - n - 1];
}
}

for(m = counter; m < len; m++){
for(n = 0; n < len; n++){
str[m][n] = str[len-m-1][n];
}
}

printf("begin to output\n");
for(m = 0; m < len; m++){
for(n = 0; n < len; n++){
//if(str[m][n] == '\0')
//str[m][n] = '-';
//printf("[%d][%d]%c ", m, n, str[m][n]);
printf("%c", str[m][n]);
}
printf("\n");
}

return 0;
}

运行过程及结果:
$ ./a.out
Please insert a letter(A-Z): E
begin to output
AAAAAAAAA
ABBBBBBBA
ABCCCCCBA
ABCDDDCBA
ABCDEDCBA
ABCDDDCBA
ABCCCCCBA
ABBBBBBBA
AAAAAAAAA

$ ./a.out
Please insert a letter(A-Z): G
begin to output
AAAAAAAAAAAAA
ABBBBBBBBBBBA
ABCCCCCCCCCBA
ABCDDDDDDDCBA
ABCDEEEEEDCBA
ABCDEFFFEDCBA
ABCDEFGFEDCBA
ABCDEFFFEDCBA
ABCDEEEEEDCBA
ABCDDDDDDDCBA
ABCCCCCCCCCBA
ABBBBBBBBBBBA
AAAAAAAAAAAAA

代码上有人何不懂的问题可以再问我哦

回答2:

定义一个unsigned int word[7][7]={ *******}
用for(i=0;i<7;i++)
{
for(j=0;j<7;j++)
printf("%3d",word[i][j]);
printf("\n"); //每输出一行,输出一个换行符
}

回答3:

用栈实现,很容易的