Skip to content

Instantly share code, notes, and snippets.

@kharioki
Created January 10, 2019 11:47
Show Gist options
  • Save kharioki/9006389cc83e05f06307d41f3f2fa850 to your computer and use it in GitHub Desktop.
Save kharioki/9006389cc83e05f06307d41f3f2fa850 to your computer and use it in GitHub Desktop.
mario staircase c
#include <cs50.h>
#include <stdio.h>
int get_positive_int(string prompt);
int main(void)
{
int h = get_positive_int("Height: ");
for (int i = 0; i < h; i++) {
for ( int j = h - i; j > 1; j--) {
printf(" ");
}
for ( int k = 0; k < i +1; k++){
printf("#");
}
printf("\n");
}
}
int get_positive_int(string prompt) {
int n;
do {
n = get_int("%s", prompt);
} while ( n < 1 || n > 8);
return n;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment