-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtriangle_pattern.cpp
More file actions
42 lines (39 loc) · 918 Bytes
/
Copy pathtriangle_pattern.cpp
File metadata and controls
42 lines (39 loc) · 918 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
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int num = 7;
int m = 1;
int l = 1;
float temp1 = static_cast<float>(num) / 2.0; // or simply n / 2.0 if n is already a float
int temp = round(temp1);
for (int i = 1; i <= num; i++)
{
l = i;
for (int j = 1; j <= l; j++)
{
if (i > temp && j > num + 1 - i) // 4 - 4 + 3 - 1 = 2 // 4-5+2 = 3 // num+1-i
{
l--;
for (int k = 1; k < l; k++)
{
cout << " ";
}
}
else if (i == j)
{
int p = 1;
p = p + i + j;
if (p == 9)
cout << "+";
}
else
{
cout << "*";
// cout << p;
}
}
cout << endl;
}
}