-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstaircase.cpp
More file actions
50 lines (40 loc) · 795 Bytes
/
staircase.cpp
File metadata and controls
50 lines (40 loc) · 795 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
46
47
48
49
50
/*
create staircase:
1. base && height == n;
2. use '#' symbol
3. print it out.
#
##
###
####
I need to find a way to do this like python, where it prints out space * n - 1, where n decrements by 1 over time.
int spaces = n-1;
int hashes = 1;
for (int i = spaces; i >= 0; i--)
{
std::cout << ' ';
for (int j = 0; j < hashes; j++)
{
std::cout << '#';
hashes++;
}
}
*/
#include <bits/stdc++.h>
void staircase(int n)
{
int i{ 0 }, j, hashes{ 1 };
while (n > 0)
{
for (i = n - 1; i > 0; i--)std::cout << ' ';
for (j = 0; j < hashes; j++) std::cout << '#';
std::cout << '\n';
hashes++;
n--;
}
}
int main(int argc, char const *argv[])
{
staircase(8);
return 0;
}