-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmario2.c
44 lines (40 loc) · 954 Bytes
/
mario2.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
// Two-sided pyramid
// User decides how tall a pyramid should be
// From levels 1 to 8
#include <cs50.h>
#include <stdio.h>
int h;
int main(void)
{
// Prompts user to input height
do
{
h = get_int("Select the pyramid's height from levels 1 to 8: ");
}
while (h < 1 || h > 8);
// Generate and draw the half-pyramid
for (int i = 0; i < h; i++)
{
// For spaces and hashes
for (int j = 1; j <= h; j++)
{
if (i + j < h)
{
printf(" ");
}
else
{
printf("#");
}
}
// Print a space with each iteration
printf(" ");
// For the other half of the pyramid
for (int a = 0; a <= i; a++)
{
printf("#");
}
// Prints a new line with each iteration
printf("\n");
}
}