fork download
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. int n;
  7. cin>>n;
  8. for(int i=1;i<=n;i++)
  9. {
  10. for(int j=1;j<=n-i;j++)cout<<" ";
  11. for(int j=1;j<=i;j++)cout<<j;
  12. for(int j=i-1;j>=1;j--)cout<<j;
  13. for(int j=1;j<=n-i;j++)cout<<" ";
  14. cout<<"\n";
  15. }
  16. for(int i=n-1;i>=1;i--)
  17. {
  18. for(int j=1;j<=n-i;j++)cout<<" ";
  19. for(int j=1;j<=i;j++)cout<<j;
  20. for(int j=i-1;j>=1;j--)cout<<j;
  21. for(int j=1;j<=n-i;j++)cout<<" ";
  22. cout<<"\n";
  23. }
  24.  
  25. return 0;
  26. }
Success #stdin #stdout 0s 3416KB
stdin
5
stdout
    1    
   121   
  12321  
 1234321 
123454321
 1234321 
  12321  
   121   
    1