Skip to content

Instantly share code, notes, and snippets.

@mitrnsplt
Created April 17, 2014 00:37
Show Gist options
  • Save mitrnsplt/10945116 to your computer and use it in GitHub Desktop.
Save mitrnsplt/10945116 to your computer and use it in GitHub Desktop.
A solution for cs50s mario
/**
* mario.c
*
* Peter Downs
*
* Prints a half pyramid of user specified height.
*/
#include <cs50.h>
#include <stdio.h>
int main(void)
{
// ask for a number
int h = 0;
printf("How many steps high is the pyramid? ");
h = GetInt();
while (h < 0 || h > 23)
{
printf("The height must be a whole number between zero and 24. Try again: ");
h = GetInt();
}
// make half pyramid
for (int i = 0; i < h; i++)
{
// print spaces
for (int s = 0; s < h - i - 1; s++)
{
printf(" ");
}
// print hashtags
for (int x = h - i - 1; x <= h; x++)
{
printf("#");
}
printf("\n");
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment