forked from Federico-abss/CS50-intro-course
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mario.c
38 lines (34 loc) · 856 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
#include <cs50.h>
#include <stdio.h>
void pyramid(int n);
// asks for pyramid height, checks the input and then executes the function
int main(void)
{
int height = 0;
// asks for height until it is a int comprised between 1 and 8
do
{
height = get_int("Height: ");
}
while (!(height >= 1 && height <= 8));
pyramid(height);
}
// generates a ramp of hashes n tall and as large as the line number (i)
void pyramid(int n)
{
for (int i = 0; i < n; i++)
{
// prints empty spaces first
for (int k = n - i - 2; k >= 0; k--)
{
printf(" ");
}
// then the actual ramp
for (int j = 0; j <= i; j++)
{
printf("#");
}
// moves one line down
printf("\n");
}
}