第二题
#include<stdio.h>#define X { char c;while(c=getchar()!='\n'&&c!=EOF);}
int hang()
{
int n;
do
{
system("cls");
printf("请输入菱形的行数,请输入17以内正奇数:\n");
scanf("%d",&n);
X;
if(n<3||n>17||n%2==0)
{
printf("您的输入有误,请重新输入。");
sleep(1);
}
}
while(n<3||n>17||n%2==0);
return n;
}
int main(void)
{
int i,j,k,n;
char x[27]={'0','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
n=hang();
puts(" ");
for(i=0;i<=n/2+1;i++)
{
k=i;
for(j=0;j<30-i;j++)
printf(" ");
for(j=0;j<2*i-1;j++)
{
printf("%c",x[k]);
k++;
}
puts(" ");
}
for(i=n/2;i>=0;i--)
{
k=i;
for(j=0;j<30-i;j++)
printf(" ");
for(j=0;j<2*i-1;j++)
{
printf("%c",x[k]);
k++;
}
puts(" ");
}
getch();
}