-
Notifications
You must be signed in to change notification settings - Fork 24
/
mario.c
47 lines (39 loc) · 999 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
/*
https://cs50.harvard.edu/x/2023/psets/1/mario/more/
*/
#include <cs50.h>
#include <stdio.h>
int main(void)
{
// Declare height variable
int height;
// Get user input
do
{
height = get_int("Height: ");
}
while (height < 1 || height > 8);
// Outer loop / Switch to the next line of the pyramid after printing the spaces and blocks
for (int line = 0; line < height; line++)
{
// Print the spaces
for (int space = height - 1; space > line; space--)
{
printf(" ");
}
// Print the left blocks
for (int left_blocks = 0; left_blocks <= line; left_blocks++)
{
printf("#");
}
// Print the two spaces between the blocks
printf(" ");
// Print the right blocks
for (int right_blocks = 0; right_blocks <= line; right_blocks++)
{
printf("#");
}
// Go to the next line
printf("\n");
}
}