-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmario2.c
More file actions
45 lines (38 loc) · 755 Bytes
/
mario2.c
File metadata and controls
45 lines (38 loc) · 755 Bytes
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
// CHALLENGE 2
// This is CS50
// Prompt user for 1-8 (inclusive) integer n and create right aligned pyramid of height n beside left aligned pyramid of height n with 2 spaces in between
#include <stdio.h>
#include <cs50.h>
void space(int n);
void left_pyramid(int i);
int main(void)
{
int n;
do
{
n = get_int("Please enter a height from 1 - 8: \n");
}
while (n < 1 || n > 8);
for (int i = 0; i < n; i++)
{
space(n - i);
left_pyramid(i);
printf(" ");
left_pyramid(i);
printf("\n");
}
}
void space(int n)
{
for (int i = 1; i < n; i++)
{
printf(" ");
}
}
void left_pyramid(int i)
{
for (int j = 0; j <= i; j++)
{
printf("#");
}
}