forked from emiliegervais/CS50
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mario.c
45 lines (40 loc) · 947 Bytes
/
mario.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Prints one pyramid of #
// Based on World 1-1 in NES Super Mario
#include <cs50.h>
#include <stdio.h>
int get_height_int(string prompt);
void pyramid(int h);
int main(void)
{
int height = get_height_int("Height: ");
pyramid(height);
}
// Print pyramid by filling grid with space or hash characters
void pyramid(int rows)
{
for (int i = 0; i < rows; i++)
{
// Repeat for as long as num of columns is less than num of rows
for (int col = 0; col < rows; col++)
{
// Grid starts at 0 => rows - 1
// Equivalent to the current grid row => i
if (col < (rows - 1 - i))
printf(" ");
else
printf("#");
}
printf("\n");
}
}
// Prompt user for integer between 2 and 8
int get_height_int(string prompt)
{
int n;
do
{
n = get_int("%s", prompt);
}
while (n < 2 || n > 8);
return n;
}