打印 n 阶实心菱形
输入一个整数n,0 < n <= 10
输出 n 阶实心菱形 , 占 2*n-1 行
3
*
***
*****
***
*
1 #include <iostream> 2 using namespace std; 3 int main(){ 4 int n; 5 cin >> n; 6 if(0<n&&n<=10){ 7 for(int i=1;i<=n;i++){ 8 for (int j=1;j<=(2*n-1);j++){ 9 if (j>n-i && j<n+i) { 10 cout<<"*"; 11 } 12 else{ 13 cout<<" "; 14 } 15 } 16 cout<<endl; 17 } 18 for (int i=n-1;i>= 1;i--){ 19 for (int j=1;j<=(2*n-1);j++){ 20 if (j>n-i && j<n+i){ 21 cout<<"*"; 22 } 23 else { 24 cout<<" "; 25 } 26 } 27 cout<<endl; 28 } 29 } 30 }
原文:https://www.cnblogs.com/palx/p/10415608.html