
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{
int n;
while(cin>>n)
{
for(int i=0;i<n;i++)
{
for(int k=n-i-1;k>0;k--)
{
cout<<" ";
}
for(int j=0;j<i*2+1;j++)
{
cout<<"*";
}
cout<<endl;
}
for(int i=n-2;i>=0;i--)
{
for(int k=0;k<n-i-1;k++)
{
cout<<" ";
}
for(int j=i*2+1;j>0;j--)
{
cout<<"*";
}
cout<<endl;
}
}
return 0;
}
这篇博客展示了如何使用C++编程语言通过嵌套循环实现两种星形图案的输出,包括上半部分的倒三角星和下半部分的正三角星。它涉及了控制台输出和迭代的概念,适合初学者理解循环结构在图形输出中的应用。
171万+

被折叠的 条评论
为什么被折叠?



