Created
April 17, 2014 00:37
-
-
Save mitrnsplt/10945116 to your computer and use it in GitHub Desktop.
A solution for cs50s mario
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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