输出双层金字塔
输出双层金字塔
输入一个大于2的整数
输出n层的双层金字塔
2 5
* *** * * *** ***** ******* ********* ******* ***** *** *
代码如下:
#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 k=1;k<=2*i-1;k++){ cout<<"*"; } cout<<endl; } for(int i=n-1;i>=1;i--){ for(int j=1;j<=n-i;j++){ cout<<" "; } for(int k=1;k<=2*i-1;k++){ cout<<"*"; } cout<<endl; } } return 0; }
原文:https://www.cnblogs.com/Xuou7/p/14777553.html