-
-
Save anonymous/2e5ebdf5d9497d7298e9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <cs50.h> | |
int main () | |
{ | |
int height; | |
do | |
{ | |
printf("Input a height for the half pyramid:"); | |
height = GetInt(); | |
} | |
while (height < 1 || height > 23); | |
char pyramid = '\0'; | |
int r=0; // rows | |
while (r <= height) | |
{ | |
int c=0; // columns | |
while (c <= height+1) | |
{ | |
if (c >= (height-r)) // set the place for each # | |
{ | |
pyramid += '#'; | |
} | |
else | |
{ | |
pyramid += ' '; | |
} | |
c++; // goes through each column | |
} | |
pyramid += '\n'; // "create" a new arrow | |
r++; // goes through each row | |
} | |
printf("%c\n", pyramid); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment