-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathg.cpp
More file actions
60 lines (53 loc) · 958 Bytes
/
g.cpp
File metadata and controls
60 lines (53 loc) · 958 Bytes
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
#include <iostream>
using namespace std;
int findNearestOdd(int lastNum)
{
if (lastNum == 0)
{
return lastNum + 1;
}
return lastNum + 2;
}
void printStars(int n, int i, int lastNum)
{
if (n - 1 == i)
{
if (i == 0)
{
cout << "*" << endl;
}
else
{
lastNum = findNearestOdd(lastNum);
for (int j = 0; j < lastNum; j++)
{
cout << "*";
}
cout << endl;
}
}
else
{
for (int j = 0; j < n - i - 1; j++)
{
cout << " ";
}
lastNum = findNearestOdd(lastNum);
for (int j = 0; j < lastNum; j++)
{
cout << "*";
}
cout << endl;
if (n - 1 != i)
{
printStars(n, i + 1, lastNum);
}
}
}
int main()
{
int n;
cin >> n;
printStars(n, 0, 0);
return 0;
}