forked from chinhungtseng/cs50x2021
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mario.c
55 lines (39 loc) · 842 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
/*CS50x 2021
Problem Set 1: mario less*/
#include <stdio.h>
int main(void)
{
int height;
int get_height();
void right_aligned_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.
right_aligned_pyramid(height);
return 0;
}
int get_height()
{
int number;
printf("Height: ");
scanf("%i", &number);
return number;
}
void right_aligned_pyramid(int n)
{
for (int i = 0; i < n; i++) {
// print spaces.
for (int s = n-1; s > i; s--) {
printf(" ");
}
// Print hashes.
for (int h = 0; h <= i; h++) {
printf("#");
}
// Print line break.
printf("\n");
}
}