Guest User

Untitled

a guest
Jan 22nd, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <cs50.h>
  3.  
  4. void print_spaces(int num)
  5. {
  6. for(int i = 0; i < num; i++)
  7. {
  8. printf(" ");
  9. }
  10. }
  11.  
  12. void print_hashes(int num)
  13. {
  14. for(int i = 0; i < num; i++)
  15. {
  16. printf("#");
  17. }
  18. }
  19.  
  20. int main(void)
  21. {
  22. // prompt and validate user input
  23. int height, spaces, hashes;
  24.  
  25. do
  26. {
  27. height = get_int();
  28. }
  29. while(height < 0 || height > 23);
  30.  
  31. // draw the half pyramid
  32. spaces = height - 1;
  33. hashes = 2;
  34.  
  35. for (int i = 0; i < height; i++)
  36. {
  37. print_spaces(spaces);
  38. print_hashes(hashes);
  39. printf("\n");
  40. spaces--;
  41. hashes++;
  42. }
  43.  
  44. }
Add Comment
Please, Sign In to add comment