Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <cs50.h>
- void print_spaces(int num)
- {
- for(int i = 0; i < num; i++)
- {
- printf(" ");
- }
- }
- void print_hashes(int num)
- {
- for(int i = 0; i < num; i++)
- {
- printf("#");
- }
- }
- int main(void)
- {
- // prompt and validate user input
- int height, spaces, hashes;
- do
- {
- height = get_int();
- }
- while(height < 0 || height > 23);
- // draw the half pyramid
- spaces = height - 1;
- hashes = 2;
- for (int i = 0; i < height; i++)
- {
- print_spaces(spaces);
- print_hashes(hashes);
- printf("\n");
- spaces--;
- hashes++;
- }
- }
Add Comment
Please, Sign In to add comment