mario.c

Here is the reference solution for Problem Set 1, mario.c

#include <cs50.h>

#include <stdio.h>

void PrintRepeatedly(string s, int count) {

for (int i = 0; i < count; ++i) {

printf("%s", s);

}

}

int GetPyramidHeight() {

int done = 0;

int height = -1;

while (!done) {

printf("Height: ");

height = GetInt();

if (height >= 0 && height < 24) {

done = 1;

}

}

return height;

}

int main(void) {

int num_lines = GetPyramidHeight();

for (int i = 0; i < num_lines; ++i) {

PrintRepeatedly(" ", num_lines - i - 1);

PrintRepeatedly("#", i + 2);

printf("\n");

}

return 0;

}