forked from BogdanOtava/CS50x
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmario.c
38 lines (32 loc) · 747 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
/*
https://cs50.harvard.edu/x/2022/psets/1/mario/less/
*/
#include <cs50.h>
#include <stdio.h>
int main(void)
{
// Declare height variable
int height;
// Get user input
do
{
height = get_int("Height: ");
}
while (height < 1 || height > 8);
// Outer loop / Switch to next line of the pyramid after printing the spaces and blocks:
for (int line = 0; line < height; line++)
{
// Print the spaces
for (int space = height - 1; space > line; space--)
{
printf(" ");
}
// Print the blocks
for (int block = 0; block <= line; block++)
{
printf("#");
}
// Go to the next line
printf("\n");
}
}