fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. const int rows = 10;
  5.  
  6. void writeLine(const char c, const int8_t num)
  7. {
  8. if (num > 0)
  9. {
  10. std::cout << c;
  11. writeLine(c, num - 1);
  12. }
  13. }
  14.  
  15. void writePyramid(const char c, const int8_t currentRow)
  16. {
  17. if (currentRow > 0)
  18. {
  19. writeLine(' ', (2 * currentRow - 1) / 2);
  20. writeLine(c, (2 * rows) - (2 * currentRow - 1)); // problem
  21. std::endl(std::cout);
  22. writePyramid(c, currentRow - 1);
  23. }
  24. }
  25.  
  26. int main() {
  27. writePyramid('*', rows);
  28. // your code goes here
  29. return 0;
  30. }
Success #stdin #stdout 0s 3096KB
stdin
Standard input is empty
stdout
         *
        ***
       *****
      *******
     *********
    ***********
   *************
  ***************
 *****************
*******************