Skip to content

Commit 83ed57c

Browse files
committed
Butterfly pattern
1 parent a808e00 commit 83ed57c

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

Patterns/ButterflyPattern.cpp

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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+
13+
for (int j = 0; j < i + 1; j++)
14+
{
15+
cout << "* ";
16+
}
17+
18+
// spaces
19+
for (int j = 0; j < n - i - 1; j++)
20+
{
21+
cout << " ";
22+
}
23+
24+
// spaces
25+
for (int j = 0; j < n - i - 1; j++)
26+
{
27+
cout << " ";
28+
}
29+
30+
for (int j = 0; j < i + 1; j++)
31+
{
32+
cout << " *";
33+
}
34+
35+
cout << endl;
36+
}
37+
38+
// bottom
39+
for (int i = 0; i < n; i++)
40+
{
41+
42+
for (int j = 0; j < n - i; j++)
43+
{
44+
cout << "* ";
45+
}
46+
47+
// spaces
48+
for (int j = 0; j < i; j++)
49+
{
50+
cout << " ";
51+
}
52+
53+
// spaces
54+
for (int j = 0; j < i; j++)
55+
{
56+
cout << " ";
57+
}
58+
59+
for (int j = 0; j < n - i; j++)
60+
{
61+
cout << " *";
62+
}
63+
64+
cout << endl;
65+
}
66+
}

Patterns/ButterflyPattern.exe

44 KB
Binary file not shown.

0 commit comments

Comments
 (0)