fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5.  
  6. int n;
  7. cin >> n;
  8.  
  9. // الجزء العلوي (هرم)
  10. for (int i = 1; i <= n; i++)
  11. {
  12. for (int s = 1; s <= n - i; s++)
  13. cout << " ";
  14.  
  15. for (int j = 1; j <= 2 * i - 1; j++)
  16. cout << "*";
  17.  
  18. cout << endl;
  19. }
  20.  
  21. // الجزء السفلي (هرم مقلوب)
  22. for (int i = n - 1; i >= 1; i--)
  23. {
  24. for (int s = 1; s <= n - i; s++)
  25. cout << " ";
  26.  
  27. for (int j = 1; j <= 2 * i - 1; j++)
  28. cout << "*";
  29.  
  30. cout << endl;
  31. }
  32.  
  33. return 0;
  34. }
Success #stdin #stdout 0.01s 5320KB
stdin
4
stdout
   *
  ***
 *****
*******
 *****
  ***
   *