cat PrintStar.c
#include
int main(void)
{
int iUpRow, iDownRow;
int i;
int nMaxLine;
int nStar, nSpace;
Again:
printf("最大行*号个数(只能为单):");
scanf("%d", &nMaxLine);
if (nMaxLine % 2 == 0)
goto Again;
iUpRow = nMaxLine / 2 + 1;
iDownRow = nMaxLine - iUpRow;
for (i = 0; i < iUpRow; ++i)
{
nSpace = iUpRow - i - 1;
for (; nSpace; --nSpace)
printf(" ");
nStar = 2 * i + 1;
for (; nStar; --nStar)
printf("*");
printf("\n");
}
#if 1
for (i = 0; i < iDownRow; ++i)
{
nSpace = i + 1;
for (; nSpace; --nSpace)
printf(" ");
nStar = iDownRow * 2 - 2 * i - 1;
for (; nStar; --nStar)
printf("*");
printf("\n");
}
#endif
return 0;
}
#include
#define N 7
main()
{
char a[N][N];
int i,j;
// 1/4 up_left
for(i=0;i<=N/2;i++)for(j=0;j<=N/2;j++)
if(j>=i)a[i][j]='*';
else a[i][j]=' ';
// copy up_left to down_left
for(i=N-1;i>=N/2;i--)for(j=0;j<=N/2;j++)
a[i][j]=a[N-1-i][j];
// copy left to right
for(i=0;i
a[i][j]=a[i][N-1-j];
// printf a[N][N]
for(i=0;i
}
}
*******
*****
***
*
***
*****
*******