Skip to content

Instantly share code, notes, and snippets.

/mario.c Secret

Created July 15, 2014 00:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/2e5ebdf5d9497d7298e9 to your computer and use it in GitHub Desktop.
Save anonymous/2e5ebdf5d9497d7298e9 to your computer and use it in GitHub Desktop.
#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