Skip to content

Instantly share code, notes, and snippets.

@seagoj
Last active August 26, 2015 20:32
Show Gist options
  • Select an option

  • Save seagoj/0b4a78f4e484b075c5ef to your computer and use it in GitHub Desktop.

Select an option

Save seagoj/0b4a78f4e484b075c5ef to your computer and use it in GitHub Desktop.
cs50 mario solution
#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");
}
}
#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