Created
May 16, 2018 01:57
-
-
Save jenkshields/0d75de5e1ee6da52999aac4c2cbec7ee to your computer and use it in GitHub Desktop.
pyramid builder
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(void) | |
{ | |
int height; | |
// prompt user for positive number less than 23 | |
do | |
{ | |
height = get_int("Height of pyramid (1 - 23):"); | |
} | |
while (height < 0 || height > 23); | |
//print the pyramid as directed | |
for (int row = 1; row < (height + 1); row++) | |
{ | |
//spaces for left | |
for (int spaces = 0; spaces < (height - row); spaces++) | |
{ | |
printf(" "); | |
} | |
//hashes for left | |
for (int hashes = 0; hashes < row; hashes++) | |
{ | |
printf("#"); | |
} | |
//two space gap | |
printf(" "); | |
//hashes for right | |
for (int hashes = 0; hashes < row; hashes++) | |
{ | |
printf("#"); | |
} | |
//new line | |
printf("\n"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment