循环结构题1001(上下金字塔)正确答案
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
while(cin>>n)
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n-i;j++)
{
cout<<" ";
}
for(int z=1;z<=2*i-1;z++)
{
cout<<"*";
}
cout<<endl;
}
for(int i=n-1;i>=1;i--)
{
for(int j=1;j<=n-i;j++)
{
cout<<" ";
}
for(int z=1;z<=2*i-1;z++)
{
cout<<"*";
}
cout<<endl;
}
}
return 0;
}
using namespace std;
int main()
{
int n;
while(cin>>n)
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n-i;j++)
{
cout<<" ";
}
for(int z=1;z<=2*i-1;z++)
{
cout<<"*";
}
cout<<endl;
}
for(int i=n-1;i>=1;i--)
{
for(int j=1;j<=n-i;j++)
{
cout<<" ";
}
for(int z=1;z<=2*i-1;z++)
{
cout<<"*";
}
cout<<endl;
}
}
return 0;
}
全部评论
相关推荐
点赞 评论 收藏
分享
点赞 评论 收藏
分享
03-24 16:59
湖南人文科技学院 后端 点赞 评论 收藏
分享