c语言打印字母三角形
#include <stdio.h>
int main(int argc, const char * argv[]) {
char cost,top;
cost=getchar();
if (cost>='a'&&cost<='z') {
top='a';
}else if (cost>='A'&&cost<='Z')
{
top='A';
}
int h=cost-top;
for (int j=0; j<=h; j++) {
for (int k=h;k>j ; k--) {
printf(" ");
}
for (int l=0; l<j; l++) {
printf("%c",top+l );
}
for (int g=j; g>=0; g--) {
printf("%c",top+g);
}
printf("\n");
}
return 0;
打印结果为:
A
ABA
ABCBA
ABCDCBA