Skip to content

Commit a808e00

Browse files
committed
Hollow Diamond Pattern
1 parent 5800d23 commit a808e00

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

Patterns/HollowDiamondPattern.cpp

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
int main()
5+
{
6+
7+
int n = 4;
8+
9+
// top
10+
for (int i = 0; i < n; i++)
11+
{
12+
// spaces
13+
for (int j = 0; j < n - i - 1; j++)
14+
{
15+
cout << " ";
16+
}
17+
18+
cout << "*";
19+
20+
if (i != 0)
21+
{
22+
// spaces
23+
for (int j = 0; j < 2 * i - 1; j++)
24+
{
25+
cout << " ";
26+
}
27+
28+
cout << "*";
29+
}
30+
31+
cout << endl;
32+
}
33+
34+
// bottom
35+
for (int i = 0; i < n - 1; i++)
36+
{
37+
// spaces
38+
for (int j = 0; j < i + 1; j++)
39+
{
40+
cout << " ";
41+
}
42+
43+
cout << "*";
44+
45+
if (i != n - 2)
46+
{
47+
// spaces
48+
for (int j = 0; j < 2 * (n - i) - 5; j++)
49+
{
50+
cout << " ";
51+
}
52+
53+
cout << "*";
54+
}
55+
56+
cout << endl;
57+
}
58+
59+
return 0;
60+
}

Patterns/HollowDiamondPattern.exe

44 KB
Binary file not shown.

0 commit comments

Comments
 (0)