Last active
August 26, 2015 20:32
-
-
Save seagoj/0b4a78f4e484b075c5ef to your computer and use it in GitHub Desktop.
cs50 mario solution
This file contains hidden or 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
| #include <stdio.h> | |
| #include <cs50.h> | |
| int getHeightFromUser() | |
| { | |
| int height; | |
| do { | |
| printf("height: "); | |
| height = GetInt(); | |
| } while (0 > height || height > 25); | |
| return height; | |
| } | |
| int numberOfHashesInRow(int row) | |
| { | |
| return row + 2; | |
| } | |
| int numberOfEmptySpacesInRow(int height, int row) | |
| { | |
| return height - numberOfHashesInRow(row); | |
| } | |
| int main(void) | |
| { | |
| int height = getHeightFromUser(); | |
| for (int row = 0; row < height; row = row + 1) { | |
| for (int column = 0; column <= height; column = column + 1) { | |
| if (column <= numberOfEmptySpacesInRow(height, row)) { | |
| printf(" "); | |
| } else { | |
| printf("#"); | |
| } | |
| } | |
| printf("\n"); | |
| } | |
| } |
This file contains hidden or 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
| #include <stdio.h> | |
| #include <cs50.h> | |
| int main(void) | |
| { | |
| int height; | |
| do { | |
| printf("height: "); | |
| height = GetInt(); | |
| } while (0 > height || height > 25); | |
| for (int row = 0; row < height; row = row + 1) { | |
| for (int cursor = 0; cursor <= height; cursor = cursor + 1) { | |
| int hashesInRow = row + 2; | |
| if (cursor <= (height - hashesInRow)) { | |
| printf(" "); | |
| } else { | |
| printf("#"); | |
| } | |
| } | |
| printf("\n"); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment