//函数输出菱形
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
int n;
int i, j, k;
char c;
int m = 1;
cin >> n >> c;
int midn = (n + 1) / 2;
for (i = midn; i >0&&m<=n; i--)
{
for (j = 1; j < i; j++)
{
cout << " ";
}
for (k = 1; k <= m; k++)
{
cout << c;
}
m += 2;
cout << endl;
}
m = m - 2 - 2;
for (i = 1; i <midn && m <= n; i++)
{
for (j = 1; j <= i; j++)
{
cout << " ";
}
for (k = 1; k <= m; k++)
{
cout << c;
}
m -= 2;
cout << endl;
}
return 0;
}
【c++程序题】输出菱形
最新推荐文章于 2024-02-02 11:02:31 发布