-
Notifications
You must be signed in to change notification settings - Fork 45
/
mario.c
63 lines (43 loc) · 925 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
52
53
54
55
56
57
58
59
60
61
62
63
/*CS50x 2021
Problem Set 1: mario more*/
#include <stdio.h>
int main(void)
{
int height;
int get_height();
void print_pyramid(int n);
// prompt user for height
// if height less than 1 or greater than 8.
do {
height = get_height();
} while (height < 1 || height > 8);
// print hash-pyramid.
print_pyramid(height);
return 0;
}
int get_height()
{
int number;
printf("Height: ");
scanf("%i", &number);
return number;
}
void print_pyramid(int n)
{
for (int i = 0; i < n; i++) {
// Print left-side.
for (int s = n-1; s > i; s--) {
printf(" ");
}
for (int h = 0; h <= i; h++) {
printf("#");
}
printf(" ");
// Print right-side.
for (int h = 0; h <= i; h++) {
printf("#");
}
// Print line break.
printf("\n");
}
}