fork download
  1. #include<iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6. int height = 9, width = 5, leave = 11;
  7.  
  8. // Print tree
  9. int stars = 1;
  10. for(int row = (leave + 2 - 1)/2; row >= 1 ; row--){
  11. cout<<string(row, ' ')<<string(stars, '*')<<endl;
  12. stars += 2;
  13. }
  14.  
  15. // Print trunk
  16. int pos = (leave - width )/2 +1;
  17. for(int row = 0; row<height; row++){
  18. cout<<string(pos, ' ')<<string(width, '*')<<endl;
  19. }
  20. }
  21.  
  22.  
  23. /**
  24. Output:
  25.  
  26.   *
  27.   ***
  28.   *****
  29.   *******
  30.   *********
  31.  ***********
  32.   *****
  33.   *****
  34.   *****
  35.   *****
  36.   *****
  37.   *****
  38.   *****
  39.   *****
  40.   *****
  41.  
  42.  
  43. */
Success #stdin #stdout 0s 16064KB
stdin
Standard input is empty
stdout
      *
     ***
    *****
   *******
  *********
 ***********
    *****
    *****
    *****
    *****
    *****
    *****
    *****
    *****
    *****