Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <cs50.h>
- int main(void)
- {
- //prompt user for pyramid height
- int n;
- do
- {
- n = get_int("Height: ");
- }
- //height condition
- while (n < 0 || n > 23);
- // initialize variables, r - rows, s - space, h - hash
- int r = 0;
- int s = 0;
- int h = 0;
- //draw pyramid
- for (r = 1; r <= n; r++)
- {
- for (s = n - r; s > 0; s--)
- printf(" ");
- for (h = 24 - r; h < 24; h++)
- printf("#");
- printf(" ");
- for (h = 24 - r; h < 24; h++)
- printf("#");
- printf("\n");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement