-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmario.c
48 lines (40 loc) · 893 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
// Print a right-aligned pyramid of hashes
#include <cs50.h>
#include <stdio.h>
int get_height(string prompt);
void print_pyramid(int height);
int main(void)
{
int height = get_height("Height: ");
print_pyramid(height);
}
// Prompt user for positive integer between 1 and 8
int get_height(string prompt)
{
int n;
do
{
n = get_int("%s", prompt);
}
while (n < 1 || n > 8);
return n;
}
// Print a right-aligned pyramid of hashes of height 'height'
void print_pyramid(int height)
{
// Print n rows
for (int i = 0; i < height; i++)
{
// Formatting for right-alignment
for (int j = 0; j < height - i - 1; j++)
{
printf("%s", " ");
}
// Print k hashes on each row
for (int k = 0; k <= i; k++)
{
printf("%s", "#");
}
printf("%s", "\n");
}
}