#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int n;
char ch;
cin >> n >> ch;
/*
补全->对称
*****
***
*
*
***
*****
*/
int M = sqrt((n + 1) / 2); //重点:半边层数
//等差数列 a1+n(n-1)d/2; d=2;
for (int i = M; i >= 1; i--)
{ // 上层
for (int j = 1; j <= M - i; j++)
{
cout << ' ';
}
for (int j = 1; j <= 2 * i - 1; j++)
{
cout << ch;
}
cout << endl;
}
for (int i = 2; i <= M; i++)
{
// 下层
for (int j = 1; j <= M - i; j++)
{
cout << ' ';
}
for (int j = 1; j <= 2 * i - 1; j++)
{
cout << ch;
}
cout << endl;
}
cout << n - M * M * 2 + 1 << endl;
system("pause");
return 0;
}
打印沙漏(输出字符串)
最新推荐文章于 2024-06-18 19:18:22 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)