fork download
  1. #include <stdio.h>
  2.  
  3. void print_pyramid(int height)
  4. {
  5. for(int i = 1; i <= height; ++i)
  6. {
  7. // print spaces part of current level
  8. for (int j = 0; j < height - i; ++j)
  9. {
  10. printf(" ");
  11. }
  12.  
  13. // print block parts of current level
  14. for (int j = 0; j < i; ++j)
  15. {
  16. printf("#");
  17. }
  18. printf("\n");
  19. }
  20. }
  21.  
  22. int main(void) {
  23. int height = 0;
  24. do {
  25. printf("Pyramid height: \n");
  26. scanf("%d", &height);
  27. } while (height < 1 || height > 23);
  28.  
  29. print_pyramid(height);
  30.  
  31. return 0;
  32. }
  33.  
Success #stdin #stdout 0s 4876KB
stdin
5
stdout
Pyramid height: 
    #
   ##
  ###
 ####
#####