Skip to content

Instantly share code, notes, and snippets.

@jenkshields
Created May 16, 2018 01:57
Show Gist options
  • Save jenkshields/0d75de5e1ee6da52999aac4c2cbec7ee to your computer and use it in GitHub Desktop.
Save jenkshields/0d75de5e1ee6da52999aac4c2cbec7ee to your computer and use it in GitHub Desktop.
pyramid builder
#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