输入n表示n行
#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
for (int i = 1; i <= (n + 1) / 2; i++)
{
for (int j = 1; j <= 2 * i - 1; j++)
{
cout << "*";
}
cout << endl;
}
for (int k = 1; k <= (n-1)/2; k++)
{
for (int y = 1; y <= n - 2 * k; y++)
{
cout << "*";
}
cout << endl;
}
return 0;
}
输出以下图案:
*
***
*****
*******
*****
***
*