Last active
March 19, 2022 17:41
-
-
Save sdwvit/94c027179da8545258e9c06ba6e6261e to your computer and use it in GitHub Desktop.
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
#include <stdio.h> | |
#include <stdlib.h> | |
#include <cs50.h> | |
int getHeight(void) { | |
int height; | |
do { | |
height = get_int("Height: "); | |
} while ( | |
height <= 0 || height > 8 | |
); | |
return height; | |
} | |
int getLowerBound(int height, int gap_width, int j) { | |
return height - j - 1; | |
} | |
int getUpperBound(int height, int gap_width, int j) { | |
return height + j + gap_width; | |
} | |
int isGap(int height, int gap_width, int i) { | |
return i > height - 1 && i < height + gap_width; | |
} | |
int main(void) | |
{ | |
int height = getHeight(); | |
int gap_width = 2; | |
int line_len; | |
for (int j = 0; j < height; j++) { | |
line_len = getUpperBound(height, gap_width, j) + 1; | |
char line[line_len + 1]; | |
for (int i = 0; i < line_len; i++) { | |
line[i] = ' '; | |
if (!(i >= getLowerBound(height, gap_width, j) && i <= getUpperBound(height, gap_width, j))) { | |
continue; | |
} | |
if (isGap(height, gap_width, i)) { | |
continue; | |
} | |
line[i] = '#'; | |
} | |
line[line_len] = '\0'; // terminate char array: wtf c, that's why noone uses you | |
printf("%s\n", line); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment