-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmario.c
48 lines (42 loc) · 838 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
// Import libraries
#include <cs50.h>
#include <stdio.h>
int main(void)
{
// Prompt pyramid height
int n;
// Accept height between 1 and 8
do
{
n = get_int("Height: ");
}
while (n < 1 || n > 8);
// For height
for (int i = 1; i <= n; i++)
{
// For columns
int s = n - i;
// left space
for (int j = 0; j < s; j++)
{
printf(" ");
}
// Left block
for (int j = 0; j < i; j++)
{
printf("#");
}
// Middle space
for (int j = 0; j < 2; j++)
{
printf(" ");
}
// Right block
for (int j = 0; j < i; j++)
{
printf("#");
}
// Move to newline at the end of each column
printf("\n");
}
}