Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- #include <cs50.h>
- //this functions prompts the user for height and returns the value
- int getHeight()
- {
- int height = 0;
- //k is functioning as a boolean to check if there will be valid input or not
- int k = 0;
- //keeps looping until user enters valid input
- while(k==0)
- {
- height = get_int("Enter the height (no greater than 23)\n");
- if(height>23||height<0)
- {
- k=0;
- }
- else
- {
- k=1;
- }
- }
- return height;
- }
- //this function produces the half-pyramid
- int makePyramid()
- {
- int height = getHeight();
- for(int i = 0; i<height; i++)
- {
- int numSpaces = height - i;
- for (int k = 0; k<numSpaces; k++)
- {
- printf(" ");;
- }
- for (int x = 0; x<i+1; x++)
- {
- printf("#");
- }
- printf("\n");
- }
- return 0;
- }
- //makePyramid is called in the main
- int main(void)
- {
- makePyramid();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement