实心的:
#include
intn;
voiddraw(intn)
{
inti,j;
for(i=1-(n>>1);i<=n;i++)
if(i>=0)
{
for(j=0;jfor(j=1;j<=2*(n-i)+1;j++)printf("*");
printf("\n");
}
else
{
for(j=i;j<0;j++)printf("");
for(j=1;j<=n+2*i+1;j++)printf("*");
for(j=1;j<=-1-2*i;j++)printf("");
for(j=1;j<=n+2*i+1;j++)printf("*");
printf("\n");
}
}
intmain()
{
printf("Pleaseinputthesize(n>=4):");
scanf("%d",&n);
draw(n);
return0;
}
空心的:
#include
intn;
voiddraw(intn)
{
inti,j;
for(i=1-(n>>1);i<=n;i++)
if(i>0)
{
for(j=0;jfor(j=1;j<=2*(n-i)+1;j++)
if(j==1||j==2*(n-i)+1)printf("*");
elseprintf("");
printf("\n");
}
else
if(i==0)
{
printf("*");
for(j=1;j
for(j=1;j
}
else
{
for(j=i;j<0;j++)printf("");
for(j=1;j<=n+2*i+1;j++)
if(i==1-(n>>1))printf("*");
elseif(j==1||j==n+2*i+1)printf("*");
elseprintf("");
for(j=1;j<=-1-2*i;j++)printf("");
for(j=1;j<=n+2*i+1;j++)
if(i==1-(n>>1))printf("*");
elseif(j==1||j==n+2*i+1)printf("*");
elseprintf("");
printf("\n");
}
}
intmain()
{
printf("Pleaseinputthesize(n>=4):");
scanf("%d",&n);
draw(n);
return0;
}