Advertisement
Guest User

pyramid in c

a guest
Feb 8th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <cs50.h>
  3.  
  4. int main(void)
  5. {
  6. int pyramidSteps = 0;
  7.  
  8. printf ("Please enter a positive integer no greater than 23: ");
  9.  
  10. pyramidSteps = GetInt();
  11.  
  12. while (pyramidSteps <= 0 || pyramidSteps >= 23)
  13. {
  14. printf ("That is an incorrect integer. Please input an integer in the specified range: ");
  15. pyramidSteps = GetInt();
  16. }
  17.  
  18. int i = 0;
  19. for (i = 0; i < pyramidSteps; i++)
  20. {
  21. int j = 0;
  22. for (j = pyramidSteps; j >= 0; j--)
  23. {
  24. if (j > i)
  25. {
  26. printf (" ");
  27. }
  28. if (j <= i)
  29. {
  30. printf ("#");
  31. }
  32. if (j == 0)
  33. {
  34. printf("#\n");
  35. }
  36. }
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement