也可以考虑一下二维数组的方式:
#include<stdio.h>
void main()
{
int myArray[7][7];
//填充标识:"*"处以1标识," "处以默认的0标识
for (int i=0; i < 7; i++)
{
if (4 - (i + 1) >= 0)
{
for (int j1 = 0; j1 < 2 * (i + 1) - 1; j1++)
{
myArray[i][j1 + 4 - (i + 1)] = 1;
}
}
else
{
for (int j2 = 0; j2 < 7 - 2 * (i+1-4); j2++)
{
myArray[i][i + 1 - 4 + j2] = 1;
}
}
}
//打印图案
for (int m = 0; m < 7; m++)
{
for (int n = 0; n < 7; n++)
{
if (myArray[m][n] == 1)
{
printf("*");
}
else
{
printf(" ");
}
}
printf("\n");
}
}
[此贴子已经被作者于2007-10-18 11:59:47编辑过]