fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void row(int pos, int k) {
  5. for (int i = 1; i < pos; i++){
  6. cout << " ";
  7. }
  8. cout << "*";
  9. if (k >= 0) {
  10. for (int i = 1; i <= k; i++){
  11. cout << " ";
  12. }
  13. cout << "*";
  14. }
  15. cout << endl;
  16. }
  17.  
  18. int main() {
  19. int n;
  20. cin >> n;
  21. for (int t = (n + 1) / 2, k = -1;t > 0; k += 2, --t) {
  22. row(t, k);
  23. }
  24. for (int t = 1, k = n - 4;t <= (n + 1) / 2; k -= 2, ++t) {
  25. row(t, k);
  26. }
  27.  
  28. return 0;
  29. }
Success #stdin #stdout 0s 5316KB
stdin
3
stdout
 *
* *
*
 *