#include <stdio.h>
int main()
{
int i=1,n=1,a,c=0,x=0,d=0; //c剩余,d最大行
char b;
scanf("%d %c",&a,&b);
if(a>=1 && a<7)
printf("%c\n%d",b,a-1);
else{
while( n <= a )
{
i = i + 2;
n = n + (i*2);
}
n = n - i*2; i = i-2; d = i;
c = a - n;
while( i>=1 )
{
x = (d - i)/2;
while( x ) {printf(" "); x--;}
x = i;
while( x ) {printf("%c",b); x--;}
/*x = (d - i)/2;
while( x ) {printf(" "); x--;}*/
printf("\n");
i = i-2;
}
i = i+4;
while( i<=d )
{
x = (d - i)/2;
while( x ) {printf(" "); x--;}
x = i;
while( x ) {printf("%c",b); x--;}
i = i+2;
printf("\n");
}
printf("%d",c);
}
return 0;
}
1027 打印沙漏,C
最新推荐文章于 2022-11-02 14:35:08 发布
本文介绍了一个使用C语言实现的简单图形输出程序,通过输入字符和行数,可以在控制台上输出特定形状的图形。程序首先判断输入的有效性,然后通过循环和条件判断,输出由指定字符组成的图形,并在最后输出剩余行数。
1万+

被折叠的 条评论
为什么被折叠?



