Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cs50.h>
- #include <stdio.h>
- int main()
- {
- int h; // h is the user input for the height
- // i prints the no. of rows
- // j prints the spaces before the hashes
- // k prints the no. of left hashes
- // l ptints the 2gaps btw right and left pyramid
- // m prints the no. of right hashes
- do
- {
- printf("Height: ");
- h = get_int();
- }
- while (h < 0 || h > 23);
- for (int i = 0; i < h; i++) //Loop 1 controls the no. of rows
- {
- for (int j = 0; j < h - i - 1; j++) //Loop 2 controls the spaces before the hashes
- {
- printf(" ");
- }
- for (int k = 0; k <= i; k++) //Loop 3 prints the left side hash
- {
- printf("#");
- }
- for (int l = 0; l <= 2; l++) // Loop 4 prints the 2 gaps btw the right and left pyramid
- {
- printf(" ");
- }
- for (int m = 0; m <= i; m++) // Loop5 prints the right side hash
- {
- printf("#");
- }
- printf("\n");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement