fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n;
  6. cin >> n ;
  7. int ** x = new int * [n];
  8. for (int i = 0; i < n; i++) x[i] = new int[n];
  9. int m=(n-1)/2;
  10. for(int i=0;i<n;i++){
  11. for(int j=0;j<n;j++){
  12. x[i][j]=1;
  13. }
  14. for(int j=i+1;j<n-i-1;j++){
  15. x[i][j]=0;
  16. }
  17. }
  18.  
  19. for( int i=0;i<m;i++){
  20. for (int j=0;j<n;j++){
  21. if(x[i][j]==0) {
  22. x[n-i-1][j]=0;
  23. }
  24. }
  25. }
  26. for(int i=0;i<n;i++){
  27. for(int j=0;j<n;j++){
  28. if(x[i][j]!=0){
  29. cout<<"*";
  30.  
  31. } else cout<<" ";
  32. }
  33. cout<<endl;
  34. }
  35. return 0;
  36. }
Success #stdin #stdout 0.01s 5456KB
stdin
5
stdout
*   *
** **
*****
** **
*   *