题目集 打印沙漏
程序员文章站
2022-03-04 22:36:52
...
# include <stdio.h>
int main()
{
int sum,n,row;
char ch;
scanf("%d %c",&n,&ch);
while ((2*row*row-1)<=n)
row++;
sum=2*--row*row-1;
for (int i=0;i<row;i++)
{
for (int j=0;j<i;j++)
printf(" ");
for (int j=0;j<2*row-1-i*2;j++)
printf("%c",ch);
printf("\n");
}
for (int i=row-2;i>=0;i--)
{
for (int j=0;j<i;j++)
printf(" ");
for (int j=0;j<2*row-1-i*2;j++)
printf("%c",ch);
printf("\n");
}
printf("%d",n-sum);
return 0;
}