C语言金字塔知道的进,帮帮偶啦

来源:百度知道 编辑:UC知道 时间:2024/09/21 03:18:56
接收用户输入的一个大写字母,如“C”,要求输出如下字母金字塔,其中“_”代表空格:
__A
_ABA
ABCBA

具体要求:
(1) 容许接收多次输入,直到输入为“0 (零)”;
(2) 如果输入非大写字母,则给出提示,并要求重新输入;

TC2.0编译环境下已经通过,请楼主验收:
(刚才又修改了一下,让程序简单好看了些)

#include<stdio.h>

void fun(char key)
{
char temp,s, i, j;
s=key-'A';
for(i=0;i<=s;i++)
{
for(j=0;j<s-i;j++) printf(" ");
for(temp='A';temp<key-s+i;temp++) printf("%c",temp);
for(;temp>='A';temp--) printf("%c",temp);
printf("\n");
}
}

void main()
{
char key;
do
{
printf("Input a capital letter:");
scanf("%c",&key);
getchar();
if(key>='A' && key<='Z')
fun(key);
else
if(key!='0')
printf("Error!\n");
}while(key!='0');
}

#include "stdio.h"

void main()
{
char input;
int row,column,i,j;

do{
fflush( stdin );
printf("please input a c