-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday2patterns.cpp
More file actions
67 lines (54 loc) · 1.4 KB
/
day2patterns.cpp
File metadata and controls
67 lines (54 loc) · 1.4 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <iostream>
using namespace std;
int main()
{
// hollow diamond patter
/*
this can be divided into parts top and bottom,
later on divided in 3 parts - space/star/space
combination of space decreasingg reverse pattern, then target spaces in the middle and then the space increasing pattern
(too complex to understand , see the execution)
*/
int n;
cout << "Enter a number : ";
cin >> n;
cout << "hollow diamond pattern : " << endl;
// top part
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n - i - 1; j++)
{
cout << " ";
}
cout << ('*');
// in this loop we are printing the same stars just increasing the space based on the previous left star
if (i != 0)
{
for (int k = 0; k < 2 * i - 1; k++) // this calculates the space from the start
{
cout << " ";
}
cout << ('*');
}
cout << endl;
}
// bottom part
for (int i = 0; i < n - 1; i++)
{
for (int j = 0; j < i + 1; j++)
{
cout << " ";
}
cout << ('*');
if (i != n - 2)
{
for (int j = 0; j < 2 * (n - i) - 5; j++)
{
cout << " ";
}
cout << ('*');
}
cout << endl;
}
return 0;
}