#include<bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; if(n==1) cout<<"1"<<endl; else { for(int i=1;i<=n;i++)//打印上半部分 { int k=0; for(int j=1;j<=n-i;j++){ cout<<" "; } for(int j=1;j<=2*i-1;j++){ if(j<=i){ k++; } else{ k--; } cout<<k; } cout<<endl; } for(int i=n-1;i>=1;i--)//打印下半部分 { int k=0; for(int j=1;j<(n-i+1);j++){ cout<<" "; } for(int j=2*(i-1)+1;j>=1;j--){ if(j>=i){ k++; } else{ k--; } cout<<k; } cout<<endl; } } return 0; } |
Double click to view unformatted code.