forked from iamAnki/CPP-Programs-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbutterfly_star_pattern.cpp
41 lines (41 loc) · 952 Bytes
/
butterfly_star_pattern.cpp
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
#include <iostream>
using namespace std;
int main()
{
int i, j, n;
cout <<"Enter Number\n";
cin >> n;
// upper half of the pattern
for(i = 0; i < n; i++)
{
for(j = 0; j < (2 * n); j++)
{
if(i >= j) // upper left triangle
cout << "*";
else
cout << " ";
if(i >= (2 * n - 1) - j) // upper right triangle
cout << "*";
else
cout << " ";
}
cout << "\n";
}
// bottom half of the pattern
for(i = 0; i < n; i++)
{
for(j = 0; j < (2 * n); j++)
{
if(i + j <= n - 1) // bottom left triangle
cout << "*";
else
cout << " ";
if((i + n) <= j) // bottom right triangle
cout << "*";
else
cout << " ";
}
cout << "\n";
}
return 0;
}