-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPattern_44.cpp
57 lines (52 loc) · 1 KB
/
Pattern_44.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <iostream>
using namespace std;
int main()
{
int n;
cout << "Enter the number of rows : ";
cin >> n;
// Upper
for (int i = 0; i <= n; i++)
{
for (int j = 0; j < n - i; j++)
{
cout << " ";
}
for (int star = 0; star < 2 * i + 1; star++)
{
if(star == 0 || star == 2*i)cout<<"* ";
else cout<<" ";
}
cout << endl;
}
// Lower
for (int i = n - 1; i >= 0; i--)
{
for (int j = 0; j < n - i; j++)
{
cout << " ";
}
for (int star = 0; star < 2 * i + 1; star++)
{
if(star == 0 || star == 2*i)cout<<"* ";
else cout<<" ";
}
cout << endl;
}
return 0;
}
/*
Output
Enter the number of rows : 5
*
* *
* *
* *
* *
* *
* *
* *
* *
* *
*
*/