列印空心字元菱形
阿新 • • 發佈:2018-12-29
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
/* 空心數字梯形 */
/* written by Chen Gengru */
/* updated on 2018-11-19 */
int main()
{
char cStart;
int iLine;
int i, j;
scanf("%c%d", &cStart, &iLine);
for (i = 1; i <= iLine; i++)
{
for (j = iLine-i; j > 0; j--)
{
printf(" ");
}
printf("%c", cStart+i-1);
for (j = 1; j <= 2*i-3; j++)
{
if (j > 0)
{
printf(" ");
}
}
if (i > 1)
{
printf("%c", cStart+i-1);
}
printf("\n");
}
for (i = 1; i < iLine; i++)
{
for (j = 1; j <= i; j++)
{
printf(" " );
}
printf("%c", cStart+iLine-i-1);
for (j=1; j <= 2*(iLine-i)-3; j++)
{
printf(" ");
}
if (i < iLine-1)
{
printf("%c", cStart+iLine-i-1);
}
printf("\n");
}
return 0;
}