代码如下:
int main(void) { char ch; int i,j; printf("请输入一个大写字母:"); scanf("%c", &ch); i = ch - 'A' + 1; for (j = 1; j <= i; j++) { //空格的循环 int space; for(space=i-j+1; space >=1; space--) { printf(" "); } //正序字母的循环 int n1; char ch1; for (ch1 = 'A', n1 = 1; n1 < j; n1++, ch1++) { printf("%c", ch1); } //倒序字母的循环 int n2; char ch2; for (ch2 = 'A'+j-1, n2 = i; n2 >=1&&ch2>='A'; n2--,ch2--) { printf("%c", ch2); } printf("\n"); } return 0; }