Advertisement
Guest User

Untitled

a guest
Dec 13th, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.64 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <cs50.h>
  3.  
  4. int main(void)
  5. {
  6.     //prompt user for pyramid height
  7.     int n;
  8.     do
  9.     {
  10.         n = get_int("Height: ");
  11.     }
  12.     //height condition
  13.     while (n < 0 || n > 23);
  14.  
  15.     // initialize variables, r - rows, s - space, h - hash
  16.     int r = 0;
  17.     int s = 0;
  18.     int h = 0;
  19.  
  20.     //draw pyramid
  21.     for (r = 1; r <= n; r++)
  22.     {
  23.         for (s = n - r; s > 0; s--)
  24.  
  25.             printf(" ");
  26.  
  27.         for (h = 24 - r; h < 24; h++)
  28.  
  29.             printf("#");
  30.  
  31.         printf("  ");
  32.  
  33.         for (h = 24 - r; h < 24; h++)
  34.  
  35.             printf("#");
  36.  
  37.  
  38.         printf("\n");
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement