Skip to content

Commit 5800d23

Browse files
committed
Pyramid pattern
1 parent 5f51085 commit 5800d23

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

Patterns/PyramidPattern.cpp

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
int main()
5+
{
6+
7+
int n = 4;
8+
9+
for (int i = 0; i < n; i++)
10+
{
11+
// spaces
12+
for (int j = 0; j < n - i - 1; j++)
13+
{
14+
cout << " ";
15+
}
16+
17+
// num 1
18+
for (int j = 1; j <= i + 1; j++)
19+
{
20+
cout << j;
21+
}
22+
23+
// num 2
24+
for (int j = i; j >= 1; j--)
25+
{
26+
cout << j;
27+
}
28+
29+
cout << endl;
30+
}
31+
32+
return 0;
33+
}

Patterns/PyramidPattern.exe

43.8 KB
Binary file not shown.

0 commit comments

Comments
 (0)