***
*****
*******
*****
***
*
用for语句;双重循环
#include<stdio.h>
void main()
{
int n,i,j;
printf("input n:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{ for(j=1;j<=n-i;j++)
printf(" ");
for(j=1;j<=2*i-1;j++)
printf("*");
printf("\n");
}
for(i=n-1;i>=1;i--)
{for(j=1;j<=n-i;j++)
printf(" ");
for(j=1;j<=2*i-1;j++)
printf("*");
printf("\n");}
}
有相同部分,注意看看吧
刚从一篇帖子里看到一个方法,发出来给大家共享
int iLine=1;
int main(void)
{
printf("%*s\n", 7-(iLine>4?iLine-4:4-iLine), "*******"+2*(iLine>4?iLine-4:4-iLine));
if(++iLine != 8) main();
return 0;
}