Advertisement
Guest User

mario.more

a guest
Mar 23rd, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.07 KB | None | 0 0
  1. #include <cs50.h>
  2. #include <stdio.h>
  3.  
  4. int main()
  5. {
  6.     int h; // h is the user input for the height
  7.            // i prints the no. of rows
  8.            // j prints the spaces before the hashes
  9.            // k prints the no. of left hashes
  10.            // l ptints the 2gaps btw right and left pyramid
  11.            // m prints the no. of right hashes
  12.     do
  13.     {
  14.         printf("Height: ");
  15.         h = get_int();
  16.     }
  17.     while (h < 0 || h > 23);
  18.    
  19.      for (int i = 0; i < h; i++) //Loop 1 controls the no. of rows
  20.     {
  21.         for (int j = 0; j < h - i - 1; j++) //Loop 2 controls the spaces before the hashes
  22.         {
  23.             printf(" ");
  24.         }
  25.         for (int k = 0; k <= i; k++) //Loop 3 prints the left side hash
  26.         {
  27.             printf("#");
  28.         }
  29.         for (int l = 0; l <= 2; l++) // Loop 4 prints the 2 gaps btw the right and left pyramid
  30.         {
  31.             printf(" ");
  32.         }
  33.         for (int m = 0; m <= i; m++) // Loop5 prints the right side hash
  34.         {
  35.             printf("#");
  36.         }
  37.         printf("\n");
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement