Skip to content

Instantly share code, notes, and snippets.

@sojohnnysaid
Last active January 19, 2021 22:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sojohnnysaid/a996f0f1f5c89abdc3133fb040530b83 to your computer and use it in GitHub Desktop.
Save sojohnnysaid/a996f0f1f5c89abdc3133fb040530b83 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <cs50.h>
void print_spaces(int num);
void print_hashes(int num);
int main(void)
{
// prompt and validate user input
int height, spaces, hashes;
do
{
height = get_int("Enter a number between 0 and 24: ");
}
while(height < 0 || height > 23);
// draw the half pyramid
spaces = height - 1;
hashes = 2;
for (int i = 0; i < height; i++)
{
print_spaces(spaces);
print_hashes(hashes);
printf("\n");
spaces--;
hashes++;
}
}
//-----------my-functions-------------
void print_spaces(int num)
{
for(int i = 0; i < num; i++)
{
printf(" ");
}
}
void print_hashes(int num)
{
for(int i = 0; i < num; i++)
{
printf("#");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment