Guest User

Untitled

a guest
Dec 17th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. // Mark J Rigdon
  2. // 2018-12-11
  3. // Problem set 1
  4. // Creates a half right-aligned pyramid for Mario
  5.  
  6. #include <cs50.h>
  7. #include <stdio.h>
  8.  
  9. int main(void)
  10. {
  11. // Prompt and validate user input: integer between 0 and 23.
  12. int height;
  13. printf("Let's generate Mario's half pyramid!\n");
  14. do
  15. {
  16. height = get_int("Input: ");
  17. }
  18. // Invalid heights
  19. while (height < 0 || height > 23);
  20.  
  21. // Generate the half pyramid
  22. // Loop through the height of the pyramid
  23. for (int i = 0; i < height; i++)
  24. {
  25. int number_of_spaces = (height - 1) - i;
  26. int number_of_hashes = i + 2;
  27.  
  28. // Print the spaces
  29. for (int j = 0; j < number_of_spaces; j++)
  30. {
  31. printf(" ");
  32. }
  33.  
  34. // Print the hashes
  35. for (int k = 0; k < number_of_hashes; k++)
  36. {
  37. printf("#");
  38. }
  39.  
  40. // Generate new line
  41. printf("\n");
  42. }
  43. }
Add Comment
Please, Sign In to add comment