Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#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
{
printf("enter a number between 1 and 22: ");
height = get_int();
}
while(height < 0 || height > 23);
// draw the half pyramid
spaces = height - 1;
hashes = 1;
for (int i = 0; i < height; i++)
{
print_spaces(spaces);
print_hashes(hashes);
printf(" ");
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