算法:
1.x=3,y=1;
2.打印第一行,x个空格,y个星;
3.x=x-1;y=y+2;
4.while 未到第五行 goto 2;否则goto 5;
5.x=x+1;y=y-2;
6.打印到最后;
代码:
#include <iostream>
using namespace std;
int main()
{
int n=7;
int x=3, y=1;
int i,j,k;
for (i=1; i<4; i++)
{
for (j=1; j<=x; j++)
{
cout << " ";
}
for (k=1; k<=y; k++)
{
cout << "*";
}
cout << endl;
x-=1;
y+=2;
}
for (i=1; i<4; i++)
{
x+=1;
y-=2;
for (j=1; j<=x; j++)
{
cout << " ";
}
for (k=1; k<=y; k++)
{
cout << "*";
}
cout << endl;
}
return 0;
}
运行结果:
*
***
*****
*****
***
*