-
Notifications
You must be signed in to change notification settings - Fork 0
/
mario.c
51 lines (46 loc) · 923 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
46
47
48
49
50
51
#include <cs50.h>
#include <stdio.h>
#include <ctype.h>
// get height from user input
// only return if certain conditions are met
int get_height(void)
{
int height;
char c;
while (true)
{
height = get_int("Height: ");
if (height > 0 && height < 9)
{
return height;
}
}
return 0;
}
void print_blocks(int height)
{
int j = 0;
char block[10];
// iterate rows
for (int i = 0; i < height; i++)
{
// print blank spaces leading up to start of row
for (int l = 0; l < height - i - 1; l++)
{
printf(" ");
}
for (int k = 0; k < j + 1; k++)
{
block[k] = '#';
}
// print blocks after leading spaces
printf("%s %s\n", block, block);
j++;
}
}
int main(void)
{
int height = 0;
height = get_height();
print_blocks(height);
}